Struct Viz

Source
pub struct Viz { /* private fields */ }

Implementations§

Source§

impl Viz

Source

pub fn label(self, info_header: String, info_txt: String) -> Self

Examples found in repository?
examples/expr.rs (line 214)
206fn main() {
207    {
208        use expr1::*;
209        let expr = multiply(subtract(literal(1), literal(2)), literal(3));
210
211        let (evaluated, viz) = eval(&expr);
212        assert_eq!(evaluated, -3);
213
214        viz.label("Evaluate Expr".to_string(), "(1 - 2) * 3".to_string())
215            .write("eval.html".to_string());
216
217        let (built_expr, viz) = build_expr(2);
218        let expected = add(add(literal(1), literal(1)), add(literal(1), literal(1)));
219
220        assert_eq!(built_expr, expected);
221
222        viz.label("Build Expr".to_string(), "1 + 1 + 1 + 1".to_string())
223            .write("build_expr.html".to_string());
224    }
225
226    {
227        use expr2::*;
228
229        let valid_expr = divide(subtract(literal(1), literal(7)), literal(3));
230        let invalid_expr = divide(multiply(literal(2), literal(3)), literal(0));
231
232        let (valid_res, valid_viz) = try_eval(&valid_expr);
233        let (invalid_res, invalid_viz) = try_eval(&invalid_expr);
234
235        assert_eq!(valid_res, Ok(-2));
236        assert_eq!(invalid_res, Err("cannot divide by zero"));
237
238        valid_viz
239            .label("Try Eval Valid Expr".to_string(), "(1 - 7) / 3".to_string())
240            .write("try_eval_valid.html".to_string());
241        invalid_viz
242            .label("Try Eval Expr".to_string(), "(2 * 3) / 0".to_string())
243            .write("try_eval_invalid.html".to_string());
244    }
245}
Source

pub fn fuse(self, next: Self, info_header: String, info_txt: String) -> Self

Source

pub fn write(self, path: String)

Examples found in repository?
examples/expr.rs (line 215)
206fn main() {
207    {
208        use expr1::*;
209        let expr = multiply(subtract(literal(1), literal(2)), literal(3));
210
211        let (evaluated, viz) = eval(&expr);
212        assert_eq!(evaluated, -3);
213
214        viz.label("Evaluate Expr".to_string(), "(1 - 2) * 3".to_string())
215            .write("eval.html".to_string());
216
217        let (built_expr, viz) = build_expr(2);
218        let expected = add(add(literal(1), literal(1)), add(literal(1), literal(1)));
219
220        assert_eq!(built_expr, expected);
221
222        viz.label("Build Expr".to_string(), "1 + 1 + 1 + 1".to_string())
223            .write("build_expr.html".to_string());
224    }
225
226    {
227        use expr2::*;
228
229        let valid_expr = divide(subtract(literal(1), literal(7)), literal(3));
230        let invalid_expr = divide(multiply(literal(2), literal(3)), literal(0));
231
232        let (valid_res, valid_viz) = try_eval(&valid_expr);
233        let (invalid_res, invalid_viz) = try_eval(&invalid_expr);
234
235        assert_eq!(valid_res, Ok(-2));
236        assert_eq!(invalid_res, Err("cannot divide by zero"));
237
238        valid_viz
239            .label("Try Eval Valid Expr".to_string(), "(1 - 7) / 3".to_string())
240            .write("try_eval_valid.html".to_string());
241        invalid_viz
242            .label("Try Eval Expr".to_string(), "(2 * 3) / 0".to_string())
243            .write("try_eval_invalid.html".to_string());
244    }
245}

Trait Implementations§

Source§

impl Clone for Viz

Source§

fn clone(&self) -> Viz

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 Viz

§

impl RefUnwindSafe for Viz

§

impl Send for Viz

§

impl Sync for Viz

§

impl Unpin for Viz

§

impl UnwindSafe for Viz

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.