Struct glib::closure::RustClosure
source · [−]pub struct RustClosure(_);
Implementations
sourceimpl 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
sourceimpl AsRef<Closure> for RustClosure
impl AsRef<Closure> for RustClosure
sourceimpl Clone for RustClosure
impl Clone for RustClosure
sourcefn clone(&self) -> RustClosure
fn clone(&self) -> RustClosure
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for RustClosure
impl Debug for RustClosure
sourceimpl From<RustClosure> for Closure
impl From<RustClosure> for Closure
sourcefn from(c: RustClosure) -> Self
fn from(c: RustClosure) -> Self
Converts to this type from the input type.
sourceimpl Hash for RustClosure
impl Hash for RustClosure
sourceimpl Ord for RustClosure
impl Ord for RustClosure
sourceimpl PartialEq<RustClosure> for RustClosure
impl PartialEq<RustClosure> for RustClosure
sourcefn eq(&self, other: &RustClosure) -> bool
fn eq(&self, other: &RustClosure) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &RustClosure) -> bool
fn ne(&self, other: &RustClosure) -> bool
This method tests for !=
.
sourceimpl PartialOrd<RustClosure> for RustClosure
impl PartialOrd<RustClosure> for RustClosure
sourcefn partial_cmp(&self, other: &RustClosure) -> Option<Ordering>
fn partial_cmp(&self, other: &RustClosure) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Eq for RustClosure
impl StructuralEq for RustClosure
impl StructuralPartialEq for RustClosure
Auto Trait Implementations
impl RefUnwindSafe for RustClosure
impl Send for RustClosure
impl Sync for RustClosure
impl Unpin for RustClosure
impl UnwindSafe for RustClosure
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more