Struct behold::Behold [−][src]
pub struct Behold { /* fields omitted */ }
The core data structure - stores shared global context and instance specific configuration
Methods
impl Behold
[src]
impl Behold
pub fn new() -> Self
[src]
pub fn new() -> Self
Create a new Behold instance
pub fn set_context(&self, key: &str, value: bool)
[src]
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!"
pub fn tag(&self, tag: &str) -> Self
[src]
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"
pub fn when(&self, speak_up: bool) -> Self
[src]
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"
pub fn when_context(&self, key: &str) -> Self
[src]
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!"
pub fn show(&self, msg: String)
[src]
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!"
pub fn call(&self, f: &Fn())
[src]
pub fn call(&self, f: &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.