1use crate::{
2 Result,
3};
4use std::borrow::Cow;
5
6pub trait Value<T> {
11 fn parse_value(text: Cow<'_, str>) -> Result<T>;
13}
14
15pub struct ValueDefault;
17
18impl<T> Value<T> for ValueDefault
19where
20 T: std::str::FromStr,
21 T::Err: std::error::Error + 'static,
22{
23 fn parse_value(text: Cow<'_, str>) -> Result<T> {
24 Ok(text.parse::<T>()?)
25 }
26}
27
28pub struct ValueString;
30
31impl Value<String> for ValueString {
32 fn parse_value(text: Cow<'_, str>) -> Result<String> {
33 Ok(text.into_owned())
34 }
35}
36
37impl<'a> Value<Cow<'a, str>> for ValueString {
38 fn parse_value(text: Cow<'_, str>) -> Result<Cow<'a, str>> {
39 Ok(Cow::Owned(text.into_owned()))
40 }
41}