pub struct RustClosure(/* private fields */);
Implementations§
Source§impl RustClosure
impl RustClosure
Sourcepub fn new<F: Fn(&[Value]) -> Option<Value> + Send + Sync + 'static>(
callback: F,
) -> Self
pub fn new<F: Fn(&[Value]) -> Option<Value> + Send + Sync + 'static>( callback: F, ) -> Self
Creates a new closure around a Rust closure.
See glib::closure!
for a way to create a closure with concrete
types.
§Panics
Invoking the closure with wrong argument types or returning the wrong return value type will panic.
§Example
use glib::prelude::*;
let closure = glib::RustClosure::new(|values| {
let x = values[0].get::<i32>().unwrap();
Some((x + 1).to_value())
});
assert_eq!(
closure.invoke::<i32>(&[&1i32]),
2,
);
Sourcepub fn new_local<F: Fn(&[Value]) -> Option<Value> + 'static>(
callback: F,
) -> Self
pub fn new_local<F: Fn(&[Value]) -> Option<Value> + 'static>( callback: F, ) -> Self
Creates a new closure around a Rust closure.
See glib::closure_local!
for a way to create a closure with
concrete types.
§Panics
Invoking the closure with wrong argument types or returning the wrong return value type will panic.
Invoking the closure from a different thread than this one will panic.
Sourcepub fn invoke<R: TryFromClosureReturnValue>(&self, values: &[&dyn ToValue]) -> R
pub fn invoke<R: TryFromClosureReturnValue>(&self, values: &[&dyn ToValue]) -> R
Invokes the closure with the given arguments.
For invalidated closures this returns the “default” value of the return type. For nullable
types this is None
, which means that e.g. requesting R = String
will panic will R = Option<String>
will return None
.
§Panics
The argument types and return value type must match the ones expected by the closure or otherwise this function panics.
Sourcepub fn invoke_with_values(
&self,
return_type: Type,
values: &[Value],
) -> Option<Value>
pub fn invoke_with_values( &self, return_type: Type, values: &[Value], ) -> Option<Value>
Invokes the closure with the given arguments.
For invalidated closures this returns the “default” value of the return type.
§Panics
The argument types and return value type must match the ones expected by the closure or otherwise this function panics.
Sourcepub fn invalidate(&self)
pub fn invalidate(&self)
Invalidates the closure.
Invoking an invalidated closure has no effect.
Trait Implementations§
Source§impl AsRef<Closure> for RustClosure
impl AsRef<Closure> for RustClosure
Source§impl Clone for RustClosure
impl Clone for RustClosure
Source§fn clone(&self) -> RustClosure
fn clone(&self) -> RustClosure
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for RustClosure
impl Debug for RustClosure
Source§impl From<RustClosure> for Closure
impl From<RustClosure> for Closure
Source§fn from(c: RustClosure) -> Self
fn from(c: RustClosure) -> Self
Source§impl Hash for RustClosure
impl Hash for RustClosure
Source§impl Ord for RustClosure
impl Ord for RustClosure
Source§fn cmp(&self, other: &RustClosure) -> Ordering
fn cmp(&self, other: &RustClosure) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for RustClosure
impl PartialEq for RustClosure
Source§impl PartialOrd for RustClosure
impl PartialOrd for RustClosure
impl Eq for RustClosure
impl StructuralPartialEq for RustClosure
Auto Trait Implementations§
impl Freeze for RustClosure
impl RefUnwindSafe for RustClosure
impl Send for RustClosure
impl Sync for RustClosure
impl Unpin for RustClosure
impl UnwindSafe for RustClosure
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)