[−][src]Struct dia_assert::Assert
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
exit_code
: will be passed toprocess::exit()
.
pub fn try_with<F>(&self, f: F) -> Result<()> where
F: FnOnce() -> String,
[src]
F: FnOnce() -> String,
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 ofLevel.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]
F: Fn() -> String,
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]
F: Fn() -> String,
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
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,