pub struct Behold { /* private fields */ }
Expand description
The core data structure - stores shared global context and instance specific configuration
Implementations§
Source§impl Behold
impl Behold
Sourcepub fn set_context(&self, key: &str, value: bool)
pub fn set_context(&self, key: &str, value: bool)
Set the value of the global Behold context
§Examples
use behold::behold;
behold().when_context("do-it").show("Hello world!".to_string())
Will output nothing.
use behold::behold;
behold().set_context("do-it", true);
behold().when_context("do-it").show("Hello world!".to_string())
Will produce the output:
ⓘ
"Hello world!"
Sourcepub fn when(&self, speak_up: bool) -> Self
pub fn when(&self, speak_up: bool) -> Self
Produce a behold instance which can speak up or not, depending on the parameter
§Examples
use behold::behold;
behold().when(0 % 2 == 1).show("Hello world!".to_string())
Will output nothing.
use behold::behold;
behold().when(0 % 2 == 0).show("Hello world!".to_string())
Will output
ⓘ
"Hello world!, apples"
Sourcepub fn when_context(&self, key: &str) -> Self
pub fn when_context(&self, key: &str) -> Self
Produce a behold instance which can speak up or not, depending on the specified context
§Examples
use behold::behold;
behold().when_context("do-it").show("Hello world!".to_string())
Will output nothing.
use behold::behold;
behold().set_context("do-it", true);
behold().when_context("do-it").show("Hello world!".to_string())
Will output
ⓘ
"Hello world!"
Sourcepub fn call(&self, f: &dyn Fn())
pub fn call(&self, f: &dyn Fn())
Call the provided function if this behold instance is configured to speak up
§Examples
use behold::behold;
behold().call(&|| { println!("Hello world!"); } );
Will output:
ⓘ
"Hello world!"
Whereas the following:
use behold::behold;
behold().when(false).call(&|| { println!("Hello world!"); } );
Will output nothing.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Behold
impl RefUnwindSafe for Behold
impl Send for Behold
impl Sync for Behold
impl Unpin for Behold
impl UnwindSafe for Behold
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
Mutably borrows from an owned value. Read more