pub trait CallbackReturn {
type FoldType: Default;
// Required method
fn fold_callback_return(folded: Self::FoldType, ret: Self) -> Self::FoldType;
// Provided method
fn callback_fold_default() -> Self::FoldType { ... }
}Expand description
A type which can be returned from a callback and folded into a single value
As an example, here’s the provided implementation for bool:
/// Returns true if any of the callbacks returned true without short circuiting
impl CallbackReturn for bool {
type FoldType = bool;
fn fold_callback_return(folded: Self::FoldType, ret: Self) -> Self::FoldType {
folded | ret
}
}The way this is used is by taking the FoldType and creating a default instance. For
a bool this will be false. Then, for each callback return value it will take the
previous instance (starting with false) and do previous | current_callback_return.
The result will mean that if callbacks a, b, and c are registered, the resulting
value returned from <callback>::trigger(...) is ((false | a) | b) | c. (Parenthesis
added to demonstrate folding order)
Required Associated Types§
Required Methods§
Sourcefn fold_callback_return(folded: Self::FoldType, ret: Self) -> Self::FoldType
fn fold_callback_return(folded: Self::FoldType, ret: Self) -> Self::FoldType
Function for folding each callback return value into a single value
Provided Methods§
Sourcefn callback_fold_default() -> Self::FoldType
fn callback_fold_default() -> Self::FoldType
Get the default value for folding the callback returns into a single value
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl CallbackReturn for bool
Returns true if any of the callbacks returned true without short circuiting
impl CallbackReturn for bool
Returns true if any of the callbacks returned true without short circuiting
Source§impl CallbackReturn for i8
Returns the first non-zero value without short-circuiting
impl CallbackReturn for i8
Returns the first non-zero value without short-circuiting
Source§impl CallbackReturn for i16
Returns the first non-zero value without short-circuiting
impl CallbackReturn for i16
Returns the first non-zero value without short-circuiting
Source§impl CallbackReturn for i32
Returns the first non-zero value without short-circuiting
impl CallbackReturn for i32
Returns the first non-zero value without short-circuiting
Source§impl CallbackReturn for i64
Returns the first non-zero value without short-circuiting
impl CallbackReturn for i64
Returns the first non-zero value without short-circuiting
Source§impl CallbackReturn for isize
Returns the first non-zero value without short-circuiting
impl CallbackReturn for isize
Returns the first non-zero value without short-circuiting
Source§impl CallbackReturn for u8
Returns the first non-zero value without short-circuiting
impl CallbackReturn for u8
Returns the first non-zero value without short-circuiting
Source§impl CallbackReturn for u16
Returns the first non-zero value without short-circuiting
impl CallbackReturn for u16
Returns the first non-zero value without short-circuiting
Source§impl CallbackReturn for u32
Returns the first non-zero value without short-circuiting
impl CallbackReturn for u32
Returns the first non-zero value without short-circuiting
Source§impl CallbackReturn for u64
Returns the first non-zero value without short-circuiting
impl CallbackReturn for u64
Returns the first non-zero value without short-circuiting
Source§impl CallbackReturn for usize
Returns the first non-zero value without short-circuiting
impl CallbackReturn for usize
Returns the first non-zero value without short-circuiting