Struct Behold

Source
pub struct Behold { /* private fields */ }
Expand description

The core data structure - stores shared global context and instance specific configuration

Implementations§

Source§

impl Behold

Source

pub fn new() -> Self

Create a new Behold instance

Source

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!"
Source

pub fn tag(&self, tag: &str) -> Self

Return a Behold instance that appends output with the specified tag

§Examples
use behold::behold;
behold().tag("apples").show("Hello world!".to_string());

Will produce the output:

"Hello world!, apples"
Source

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"
Source

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!"
Source

pub fn show(&self, msg: String)

Print the provided string if this behold instance is configured to speak up

§Examples
use behold::behold;
behold().show("Hello world!".to_string());

Will produce the output:

"Hello world!"
Source

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§

Source§

impl Clone for Behold

Source§

fn clone(&self) -> Behold

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.