1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use crate::{by_ref::ByRef, err::Result, from_arg::FromArg};

/// This trait represents a string reference object that can be parsed into a
/// type.
pub trait ArgInto<'a> {
    /// Parses this string into another type using the [`FromArg`] trait.
    ///
    /// # Examples
    /// ```rust
    /// use pareg_core::ArgInto;
    ///
    /// assert_eq!("hello", "hello".arg_into::<&str>().unwrap());
    /// assert_eq!(5, "5".arg_into::<i32>().unwrap());
    /// ```
    fn arg_into<T>(self) -> Result<T>
    where
        T: FromArg<'a>;
}

impl<'a, S> ArgInto<'a> for S
where
    S: ByRef<&'a str>,
{
    #[inline(always)]
    fn arg_into<T>(self) -> Result<T>
    where
        T: FromArg<'a>,
    {
        T::from_arg(self.by_ref())
    }
}