use crate::func::args::{Arg, ArgError};
use crate::{Reflect, TypePath};
pub trait FromArg {
type This<'a>;
fn from_arg(arg: Arg<'_>) -> Result<Self::This<'_>, ArgError>;
}
impl<T: Reflect + TypePath> FromArg for &'static T {
type This<'a> = &'a T;
fn from_arg(arg: Arg<'_>) -> Result<Self::This<'_>, ArgError> {
arg.take_ref()
}
}
impl<T: Reflect + TypePath> FromArg for &'static mut T {
type This<'a> = &'a mut T;
fn from_arg(arg: Arg<'_>) -> Result<Self::This<'_>, ArgError> {
arg.take_mut()
}
}
macro_rules! impl_from_arg {
(
$ty: ty
$(;
< $($T: ident $(: $T1: tt $(+ $T2: tt)*)?),* >
)?
$(
[ $(const $N: ident : $size: ident),* ]
)?
$(
where $($U: ty $(: $U1: tt $(+ $U2: tt)*)?),*
)?
) => {
impl <
$($($T $(: $T1 $(+ $T2)*)?),*)?
$(, $(const $N : $size),*)?
> $crate::func::args::FromArg for $ty
$(
where $($U $(: $U1 $(+ $U2)*)?),*
)?
{
type This<'from_arg> = $ty;
fn from_arg(arg: $crate::func::args::Arg<'_>) ->
Result<Self::This<'_>, $crate::func::args::ArgError>
{
arg.take_owned()
}
}
};
}
pub(crate) use impl_from_arg;