Struct dia_assert::Assert
[−]
[src]
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) -> Assert
[src]
Makes new instance.
exit_code
: will be passed toprocess::exit()
.
pub fn try_with<F, S>(&self, f: F) -> Result<(), Failed> where
F: FnOnce() -> S,
S: AsRef<str>,
[src]
F: FnOnce() -> S,
S: AsRef<str>,
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.
pub fn try_n_with<F, S>(&self, n: u8, f: F) where
F: Fn() -> S,
S: AsRef<str>,
[src]
F: Fn() -> S,
S: AsRef<str>,
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, S>(&self, f: F) where
F: Fn() -> S,
S: AsRef<str>,
[src]
F: Fn() -> S,
S: AsRef<str>,
Tries once.
This function calls try_n_with()
with 1
passed as n
.
pub fn try<T: AsRef<Level>>(&self, level: T) -> Result<(), Failed>
[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
.