Struct RustClosure
pub struct RustClosure(/* private fields */);Implementations§
§impl RustClosure
impl RustClosure
pub fn new<F>(callback: F) -> RustClosure
pub fn new<F>(callback: F) -> RustClosure
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,
);pub fn new_local<F>(callback: F) -> RustClosure
pub fn new_local<F>(callback: F) -> RustClosure
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.
pub fn invoke<R>(&self, values: &[&dyn ToValue]) -> Rwhere
R: TryFromClosureReturnValue,
pub fn invoke<R>(&self, values: &[&dyn ToValue]) -> Rwhere
R: TryFromClosureReturnValue,
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.
pub 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.
pub fn invalidate(&self)
pub fn invalidate(&self)
Invalidates the closure.
Invoking an invalidated closure has no effect.
Trait Implementations§
§impl AsRef<Closure> for RustClosure
impl AsRef<Closure> for RustClosure
§impl Clone for RustClosure
impl Clone for RustClosure
§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 more§impl Debug for RustClosure
impl Debug for RustClosure
§impl From<RustClosure> for Closure
impl From<RustClosure> for Closure
§fn from(c: RustClosure) -> Closure
fn from(c: RustClosure) -> Closure
§impl Hash for RustClosure
impl Hash for RustClosure
§impl Ord for RustClosure
impl Ord for RustClosure
§impl PartialEq for RustClosure
impl PartialEq for RustClosure
§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,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more