[][src]Struct dia_assert::Assert

pub struct Assert { /* fields omitted */ }

Use this struct with Level to assert a user action

Methods

impl Assert[src]

pub fn new(exit_code: i32) -> Self[src]

Makes new instance

pub fn try_with<F>(&self, f: F) -> Result<()> where
    F: FnOnce() -> String
[src]

Tries an assert with your own string

Sometimes you need to print your own messages and/or your verification string, instead of the pre-defined ones provided by this crate. This function can help you with that.

  • Inside closure f, you can print your messages.
  • Then f returns the string to be verified. You can make use of Level.rand_s() if you want to.

The function will read user input from stdin and verify it. Note that case is ignored. If the user fails, an error with kind of InvalidInput will be returned.

pub fn try_n_with<F>(&self, n: u8, f: F) where
    F: Fn() -> String
[src]

Tries n times

This function calls try_with().

  • If the user passed, it returns peacefully.
  • For other cases (the user fails, or stdout failure...), it calls process::exit() with the exit code you provided in ::new().

pub fn try_once_with<F>(&self, f: F) where
    F: Fn() -> String
[src]

Tries once

This function calls try_n_with() with 1 passed as n.

pub fn try<T: AsRef<Level>>(&self, level: T) -> Result<()>[src]

Tries an assert

The function generates a string with difficulty based on level. Then asks the user to type that string.

pub fn try_n<T: AsRef<Level>>(&self, level: T, n: u8)[src]

Tries n times

This function calls try().

  • If the user passed, it returns peacefully.
  • For other cases (the user fails, or stdout failure...), it calls process::exit() with the exit code you provided in ::new().

pub fn try_once<T: AsRef<Level>>(&self, level: T)[src]

Tries once

This function calls try_n() with 1 passed as n.

Auto Trait Implementations

impl Send for Assert

impl Sync for Assert

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]