Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit 2719d43

Browse files
Remove Into from manual code
1 parent 1e5b617 commit 2719d43

File tree

6 files changed

+32
-47
lines changed

6 files changed

+32
-47
lines changed

src/main_context_channel.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,11 @@ impl<T> Receiver<T> {
444444
///
445445
/// This function panics if called from a thread that is not the owner of the provided
446446
/// `context`, or, if `None` is provided, of the thread default main context.
447-
pub fn attach<'a, P: Into<Option<&'a MainContext>>, F: FnMut(T) -> Continue + 'static>(
447+
pub fn attach<F: FnMut(T) -> Continue + 'static>(
448448
mut self,
449-
context: P,
449+
context: Option<&MainContext>,
450450
func: F,
451451
) -> SourceId {
452-
let context = context.into();
453452
unsafe {
454453
let channel = self.0.take().expect("Receiver without channel");
455454

@@ -499,11 +498,11 @@ impl<T> Receiver<T> {
499498
let source = Source::from_glib_full(mut_override(&(*source).source));
500499
let id = if let Some(context) = context {
501500
assert!(context.is_owner());
502-
source.attach(context)
501+
source.attach(Some(context))
503502
} else {
504503
let context = MainContext::ref_thread_default();
505504
assert!(context.is_owner());
506-
source.attach(&context)
505+
source.attach(Some(&context))
507506
};
508507

509508
id
@@ -577,7 +576,7 @@ mod tests {
577576
let sum = Rc::new(RefCell::new(0));
578577
let sum_clone = sum.clone();
579578
let l_clone = l.clone();
580-
receiver.attach(&c, move |item| {
579+
receiver.attach(Some(&c), move |item| {
581580
*sum_clone.borrow_mut() += item;
582581
if *sum_clone.borrow() == 6 {
583582
l_clone.quit();
@@ -613,7 +612,7 @@ mod tests {
613612
}
614613

615614
let helper = Helper(l.clone());
616-
receiver.attach(&c, move |_| {
615+
receiver.attach(Some(&c), move |_| {
617616
let _ = helper;
618617

619618
Continue(true)
@@ -640,7 +639,7 @@ mod tests {
640639

641640
let (sender, receiver) = MainContext::channel::<i32>(Priority::default());
642641

643-
let source_id = receiver.attach(&c, move |_| Continue(true));
642+
let source_id = receiver.attach(Some(&c), move |_| Continue(true));
644643

645644
let source = c.find_source_by_id(&source_id).unwrap();
646645
source.destroy();
@@ -665,7 +664,7 @@ mod tests {
665664

666665
let dropped = Arc::new(Mutex::new(false));
667666
let helper = Helper(dropped.clone());
668-
let source_id = receiver.attach(&c, move |_| {
667+
let source_id = receiver.attach(Some(&c), move |_| {
669668
let _helper = &helper;
670669
Continue(true)
671670
});
@@ -692,7 +691,7 @@ mod tests {
692691
let sum = Rc::new(RefCell::new(0));
693692
let sum_clone = sum.clone();
694693
let l_clone = l.clone();
695-
receiver.attach(&c, move |item| {
694+
receiver.attach(Some(&c), move |item| {
696695
*sum_clone.borrow_mut() += item;
697696
if *sum_clone.borrow() == 6 {
698697
l_clone.quit();
@@ -741,7 +740,7 @@ mod tests {
741740
let sum = Rc::new(RefCell::new(0));
742741
let sum_clone = sum.clone();
743742
let l_clone = l.clone();
744-
receiver.attach(&c, move |item| {
743+
receiver.attach(Some(&c), move |item| {
745744
*sum_clone.borrow_mut() += item;
746745
if *sum_clone.borrow() == 6 {
747746
l_clone.quit();
@@ -843,7 +842,7 @@ mod tests {
843842
let sum = Rc::new(RefCell::new(0));
844843
let sum_clone = sum.clone();
845844
let l_clone = l.clone();
846-
receiver.attach(&c, move |item| {
845+
receiver.attach(Some(&c), move |item| {
847846
// We consumed one item so there should be one item on
848847
// the other receiver now.
849848
let _ = wait_receiver.recv().unwrap();

src/object.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -916,8 +916,8 @@ pub trait ObjectExt: ObjectType {
916916
fn emit<'a, N: Into<&'a str>>(&self, signal_name: N, args: &[&ToValue]) -> Result<Option<Value>, BoolError>;
917917
fn disconnect(&self, handler_id: SignalHandlerId);
918918

919-
fn connect_notify<'a, P: Into<Option<&'a str>>, F: Fn(&Self, &::ParamSpec) + Send + Sync + 'static>(&self, name: P, f: F) -> SignalHandlerId;
920-
unsafe fn connect_notify_unsafe<'a, P: Into<Option<&'a str>>, F: Fn(&Self, &::ParamSpec)>(&self, name: P, f: F) -> SignalHandlerId;
919+
fn connect_notify<F: Fn(&Self, &::ParamSpec) + Send + Sync + 'static>(&self, name: Option<&str>, f: F) -> SignalHandlerId;
920+
unsafe fn connect_notify_unsafe<F: Fn(&Self, &::ParamSpec)>(&self, name: Option<&str>, f: F) -> SignalHandlerId;
921921
fn notify<'a, N: Into<&'a str>>(&self, property_name: N);
922922
fn notify_by_pspec(&self, pspec: &::ParamSpec);
923923

@@ -1056,13 +1056,13 @@ impl<T: ObjectType> ObjectExt for T {
10561056
}
10571057
}
10581058

1059-
fn connect_notify<'a, P: Into<Option<&'a str>>, F: Fn(&Self, &::ParamSpec) + Send + Sync + 'static>(&self, name: P, f: F) -> SignalHandlerId {
1059+
fn connect_notify<F: Fn(&Self, &::ParamSpec) + Send + Sync + 'static>(&self, name: Option<&str>, f: F) -> SignalHandlerId {
10601060
unsafe {
10611061
self.connect_notify_unsafe(name, f)
10621062
}
10631063
}
10641064

1065-
unsafe fn connect_notify_unsafe<'a, P: Into<Option<&'a str>>, F: Fn(&Self, &::ParamSpec)>(&self, name: P, f: F) -> SignalHandlerId {
1065+
unsafe fn connect_notify_unsafe<F: Fn(&Self, &::ParamSpec)>(&self, name: Option<&str>, f: F) -> SignalHandlerId {
10661066
use std::mem::transmute;
10671067

10681068
unsafe extern "C" fn notify_trampoline<P, F: Fn(&P, &::ParamSpec)>(this: *mut gobject_ffi::GObject, param_spec: *mut gobject_ffi::GParamSpec, f: glib_ffi::gpointer)
@@ -1071,7 +1071,6 @@ impl<T: ObjectType> ObjectExt for T {
10711071
f(&Object::from_glib_borrow(this).unsafe_cast(), &from_glib_borrow(param_spec))
10721072
}
10731073

1074-
let name = name.into();
10751074
let signal_name = if let Some(name) = name {
10761075
format!("notify::{}\0", name)
10771076
} else {

src/param_spec.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ impl ParamSpec {
8383
}
8484
}
8585

86-
//pub fn set_qdata<P: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, quark: /*Ignored*/glib::Quark, data: P) {
86+
//pub fn set_qdata(&self, quark: /*Ignored*/glib::Quark, data: Option</*Unimplemented*/Fundamental: Pointer>) {
8787
// unsafe { TODO: call ffi::g_param_spec_set_qdata() }
8888
//}
8989

90-
//pub fn set_qdata_full<P: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, quark: /*Ignored*/glib::Quark, data: P, destroy: /*Unknown conversion*//*Unimplemented*/DestroyNotify) {
90+
//pub fn set_qdata_full(&self, quark: /*Ignored*/glib::Quark, data: Option</*Unimplemented*/Fundamental: Pointer>, destroy: /*Unknown conversion*//*Unimplemented*/DestroyNotify) {
9191
// unsafe { TODO: call ffi::g_param_spec_set_qdata_full() }
9292
//}
9393

@@ -185,8 +185,7 @@ impl ParamSpec {
185185
}
186186
}
187187

188-
pub fn string<'a, P: Into<Option<&'a str>>>(name: &str, nick: &str, blurb: &str, default_value: P, flags: ParamFlags) -> ParamSpec {
189-
let default_value = default_value.into();
188+
pub fn string(name: &str, nick: &str, blurb: &str, default_value: Option<&str>, flags: ParamFlags) -> ParamSpec {
190189
let default_value = default_value.to_glib_none();
191190
unsafe {
192191
from_glib_full(ffi::g_param_spec_string(name.to_glib_none().0, nick.to_glib_none().0, blurb.to_glib_none().0, default_value.0, flags.to_glib()))
@@ -229,9 +228,8 @@ impl ParamSpec {
229228
}
230229
}
231230

232-
pub fn variant<'a, P: Into<Option<&'a ::Variant>>>(name: &str, nick: &str, blurb: &str, type_: &::VariantTy, default_value: P, flags: ParamFlags) -> ParamSpec {
231+
pub fn variant(name: &str, nick: &str, blurb: &str, type_: &::VariantTy, default_value: Option<&::Variant>, flags: ParamFlags) -> ParamSpec {
233232
unsafe {
234-
let default_value = default_value.into();
235233
from_glib_none(ffi::g_param_spec_variant(name.to_glib_none().0, nick.to_glib_none().0, blurb.to_glib_none().0, type_.to_glib_none().0, default_value.to_glib_none().0, flags.to_glib()))
236234
}
237235
}

src/source.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ where F: FnMut() -> Continue + 'static {
270270
/// process exits.
271271
///
272272
/// `func` will be called when `pid` exits
273-
pub fn child_watch_add<'a, N: Into<Option<&'a str>>, F>(pid: Pid, func: F) -> SourceId
273+
pub fn child_watch_add<F>(pid: Pid, func: F) -> SourceId
274274
where F: FnMut(Pid, i32) + Send + 'static {
275275
unsafe {
276276
from_glib(glib_ffi::g_child_watch_add_full(glib_ffi::G_PRIORITY_DEFAULT, pid.0,
@@ -288,7 +288,7 @@ where F: FnMut(Pid, i32) + Send + 'static {
288288
///
289289
/// This function panics if called from a different thread than the one that
290290
/// owns the main context.
291-
pub fn child_watch_add_local<'a, N: Into<Option<&'a str>>, F>(pid: Pid, func: F) -> SourceId
291+
pub fn child_watch_add_local<F>(pid: Pid, func: F) -> SourceId
292292
where F: FnMut(Pid, i32) + 'static {
293293
unsafe {
294294
assert!(MainContext::default().is_owner());
@@ -427,14 +427,13 @@ pub const PRIORITY_LOW: Priority = Priority(glib_ffi::G_PRIORITY_LOW);
427427
/// Adds a closure to be called by the main loop the return `Source` is attached to when it's idle.
428428
///
429429
/// `func` will be called repeatedly until it returns `Continue(false)`.
430-
pub fn idle_source_new<'a, N: Into<Option<&'a str>>, F>(name: N, priority: Priority, func: F) -> Source
430+
pub fn idle_source_new<F>(name: Option<&str>, priority: Priority, func: F) -> Source
431431
where F: FnMut() -> Continue + Send + 'static {
432432
unsafe {
433433
let source = glib_ffi::g_idle_source_new();
434434
glib_ffi::g_source_set_callback(source, Some(trampoline::<F>), into_raw(func), Some(destroy_closure::<F>));
435435
glib_ffi::g_source_set_priority(source, priority.to_glib());
436436

437-
let name = name.into();
438437
if let Some(name) = name {
439438
glib_ffi::g_source_set_name(source, name.to_glib_none().0);
440439
}
@@ -450,14 +449,13 @@ where F: FnMut() -> Continue + Send + 'static {
450449
/// returns `Continue(false)`. Precise timing is not guaranteed, the timeout may
451450
/// be delayed by other events. Prefer `timeout_add_seconds` when millisecond
452451
/// precision is not necessary.
453-
pub fn timeout_source_new<'a, N: Into<Option<&'a str>>, F>(interval: u32, name: N, priority: Priority, func: F) -> Source
452+
pub fn timeout_source_new<F>(interval: u32, name: Option<&str>, priority: Priority, func: F) -> Source
454453
where F: FnMut() -> Continue + Send + 'static {
455454
unsafe {
456455
let source = glib_ffi::g_timeout_source_new(interval);
457456
glib_ffi::g_source_set_callback(source, Some(trampoline::<F>), into_raw(func), Some(destroy_closure::<F>));
458457
glib_ffi::g_source_set_priority(source, priority.to_glib());
459458

460-
let name = name.into();
461459
if let Some(name) = name {
462460
glib_ffi::g_source_set_name(source, name.to_glib_none().0);
463461
}
@@ -472,14 +470,13 @@ where F: FnMut() -> Continue + Send + 'static {
472470
/// `func` will be called repeatedly every `interval` seconds until it
473471
/// returns `Continue(false)`. Precise timing is not guaranteed, the timeout may
474472
/// be delayed by other events.
475-
pub fn timeout_source_new_seconds<'a, N: Into<Option<&'a str>>, F>(interval: u32, name: N, priority: Priority, func: F) -> Source
473+
pub fn timeout_source_new_seconds<F>(interval: u32, name: Option<&str>, priority: Priority, func: F) -> Source
476474
where F: FnMut() -> Continue + Send + 'static {
477475
unsafe {
478476
let source = glib_ffi::g_timeout_source_new_seconds(interval);
479477
glib_ffi::g_source_set_callback(source, Some(trampoline::<F>), into_raw(func), Some(destroy_closure::<F>));
480478
glib_ffi::g_source_set_priority(source, priority.to_glib());
481479

482-
let name = name.into();
483480
if let Some(name) = name {
484481
glib_ffi::g_source_set_name(source, name.to_glib_none().0);
485482
}
@@ -492,14 +489,13 @@ where F: FnMut() -> Continue + Send + 'static {
492489
/// process exits.
493490
///
494491
/// `func` will be called when `pid` exits
495-
pub fn child_watch_source_new<'a, N: Into<Option<&'a str>>, F>(pid: Pid, name: N, priority: Priority, func: F) -> Source
492+
pub fn child_watch_source_new<F>(pid: Pid, name: Option<&str>, priority: Priority, func: F) -> Source
496493
where F: FnMut(Pid, i32) + Send + 'static {
497494
unsafe {
498495
let source = glib_ffi::g_child_watch_source_new(pid.0);
499496
glib_ffi::g_source_set_callback(source, Some(transmute(trampoline_child_watch::<F> as usize)), into_raw_child_watch(func), Some(destroy_closure_child_watch::<F>));
500497
glib_ffi::g_source_set_priority(source, priority.to_glib());
501498

502-
let name = name.into();
503499
if let Some(name) = name {
504500
glib_ffi::g_source_set_name(source, name.to_glib_none().0);
505501
}
@@ -514,14 +510,13 @@ where F: FnMut(Pid, i32) + Send + 'static {
514510
///
515511
/// `func` will be called repeatedly every time `signum` is raised until it
516512
/// returns `Continue(false)`.
517-
pub fn unix_signal_source_new<'a, N: Into<Option<&'a str>>, F>(signum: i32, name: N, priority: Priority, func: F) -> Source
513+
pub fn unix_signal_source_new<F>(signum: i32, name: Option<&str>, priority: Priority, func: F) -> Source
518514
where F: FnMut() -> Continue + Send + 'static {
519515
unsafe {
520516
let source = glib_ffi::g_unix_signal_source_new(signum);
521517
glib_ffi::g_source_set_callback(source, Some(trampoline::<F>), into_raw(func), Some(destroy_closure::<F>));
522518
glib_ffi::g_source_set_priority(source, priority.to_glib());
523519

524-
let name = name.into();
525520
if let Some(name) = name {
526521
glib_ffi::g_source_set_name(source, name.to_glib_none().0);
527522
}
@@ -536,14 +531,13 @@ where F: FnMut() -> Continue + Send + 'static {
536531
///
537532
/// `func` will be called repeatedly while the file descriptor matches the given IO condition
538533
/// until it returns `Continue(false)`.
539-
pub fn unix_fd_source_new<'a, N: Into<Option<&'a str>>, F>(fd: RawFd, condition: IOCondition, name: N, priority: Priority, func: F) -> Source
534+
pub fn unix_fd_source_new<F>(fd: RawFd, condition: IOCondition, name: Option<&str>, priority: Priority, func: F) -> Source
540535
where F: FnMut(RawFd, IOCondition) -> Continue + Send + 'static {
541536
unsafe {
542537
let source = glib_ffi::g_unix_fd_source_new(fd, condition.to_glib());
543538
glib_ffi::g_source_set_callback(source, Some(transmute(trampoline_unix_fd::<F> as usize)), into_raw_unix_fd(func), Some(destroy_closure_unix_fd::<F>));
544539
glib_ffi::g_source_set_priority(source, priority.to_glib());
545540

546-
let name = name.into();
547541
if let Some(name) = name {
548542
glib_ffi::g_source_set_name(source, name.to_glib_none().0);
549543
}
@@ -553,8 +547,7 @@ where F: FnMut(RawFd, IOCondition) -> Continue + Send + 'static {
553547
}
554548

555549
impl Source {
556-
pub fn attach<'a, P: Into<Option<&'a MainContext>>>(&self, context: P) -> SourceId {
557-
let context = context.into();
550+
pub fn attach(&self, context: Option<&MainContext>) -> SourceId {
558551
unsafe {
559552
from_glib(ffi::g_source_attach(self.to_glib_none().0, context.to_glib_none().0))
560553
}

src/utils.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,12 @@ pub fn get_current_dir() -> Option<PathBuf> {
117117
}
118118
}
119119

120-
pub fn filename_to_uri<'a, P: AsRef<Path>, Q: Into<Option<&'a str>>>(filename: P, hostname: Q) -> Result<GString, Error> {
120+
pub fn filename_to_uri<P: AsRef<Path>>(filename: P, hostname: Option<&str>) -> Result<GString, Error> {
121121
#[cfg(windows)]
122122
use ffi::g_filename_to_uri_utf8 as g_filename_to_uri;
123123
#[cfg(not(windows))]
124124
use ffi::g_filename_to_uri;
125125

126-
let hostname = hostname.into();
127126
let hostname = hostname.to_glib_none();
128127
unsafe {
129128
let mut error = std::ptr::null_mut();

src/value_array.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ impl ValueArray {
2828
}
2929
}
3030

31-
pub fn append<'a, P: Into<Option<&'a Value>>>(&mut self, value: P) {
32-
let value = value.into();
31+
pub fn append(&mut self, value: Option<&Value>) {
3332
let value = value.to_glib_none();
3433
unsafe {
3534
ffi::g_value_array_append(self.to_glib_none_mut().0, value.0);
@@ -42,16 +41,14 @@ impl ValueArray {
4241
}
4342
}
4443

45-
pub fn insert<'a, P: Into<Option<&'a Value>>>(&mut self, index_: u32, value: P) {
46-
let value = value.into();
44+
pub fn insert(&mut self, index_: u32, value: Option<&Value>) {
4745
let value = value.to_glib_none();
4846
unsafe {
4947
ffi::g_value_array_insert(self.to_glib_none_mut().0, index_, value.0);
5048
}
5149
}
5250

53-
pub fn prepend<'a, P: Into<Option<&'a Value>>>(&mut self, value: P) {
54-
let value = value.into();
51+
pub fn prepend(&mut self, value: Option<&Value>) {
5552
let value = value.to_glib_none();
5653
unsafe {
5754
ffi::g_value_array_prepend(self.to_glib_none_mut().0, value.0);

0 commit comments

Comments
 (0)