use crate::{
Result,
};
use std::borrow::Cow;
pub trait Value<T> {
fn parse_value(text: Cow<'_, str>) -> Result<T>;
}
pub struct ValueDefault;
impl<T> Value<T> for ValueDefault
where
T: std::str::FromStr,
T::Err: std::error::Error + 'static,
{
fn parse_value(text: Cow<'_, str>) -> Result<T> {
Ok(text.parse::<T>()?)
}
}
pub struct ValueString;
impl Value<String> for ValueString {
fn parse_value(text: Cow<'_, str>) -> Result<String> {
Ok(text.into_owned())
}
}
impl<'a> Value<Cow<'a, str>> for ValueString {
fn parse_value(text: Cow<'_, str>) -> Result<Cow<'a, str>> {
Ok(Cow::Owned(text.into_owned()))
}
}