pub trait Askable {
// Required method
fn convert<S: AsRef<str>>(s: S) -> Result<Self>
where Self: Sized;
}
Expand description
Base trait for all types that can be asked for input.
Required Methods§
Sourcefn convert<S: AsRef<str>>(s: S) -> Result<Self>where
Self: Sized,
fn convert<S: AsRef<str>>(s: S) -> Result<Self>where
Self: Sized,
Convert a string to a value of type T.
§Arguments
prompt_str
: string to convert
Returns InterviewError
if the conversion fails.
returns: Result<Self, InterviewError>
§Examples
ⓘ
use interviewer::{Askable, Result};
struct X {
x: i32
}
impl Askable for X {
fn convert<S: AsRef<str>>(s: S) -> Result<Self> {
Ok(X {
x: s.as_ref().trim().parse::<i32>()?
})
}
}