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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use std::{
borrow::Cow,
ffi::{OsStr, OsString},
rc::Rc,
sync::Arc,
};
use crate::{err::Result, from_arg::FromArg, impl_all::impl_all};
/// 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>(&'a self) -> Result<T>
where
T: FromArg<'a>;
}
impl_all! { impl<'a> ArgInto<'a>:
OsStr, OsString, Arc<OsStr>, Rc<OsStr>, Cow<'a, OsStr>, &OsStr => {
#[inline(always)]
fn arg_into<T>(&'a self) -> Result<T>
where
T: FromArg<'a>,
{
#[allow(clippy::useless_asref)]
T::from_os_arg((*self).as_ref())
}
}
}
impl_all! { impl<'a> ArgInto<'a>:
str, String, Arc<str>, Rc<str>, Cow<'a, str>, &str => {
#[inline(always)]
fn arg_into<T>(&'a self) -> Result<T>
where
T: FromArg<'a>,
{
#[allow(clippy::useless_asref)]
T::from_arg((*self).as_ref())
}
}
}