Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,12 +685,12 @@ macro_rules! quick_error {
}
$(
quick_error!(FIND_FROM_IMPL
$name $item: $imode [$( $var:$typ ),*]
$name $item: $imode [$(#[$imeta])*] [$( $var:$typ ),*]
{$( $funcs )*});
)*
$(
quick_error!(FIND_CONTEXT_IMPL
$name $item: $imode [$( $var:$typ ),*]
$name $item: $imode [$(#[$imeta])*] [$( $var:$typ ),*]
{$( $funcs )*});
)*
};
Expand Down Expand Up @@ -745,9 +745,11 @@ macro_rules! quick_error {
};
// ----------------------------- FROM IMPL --------------------------
(FIND_FROM_IMPL $name:ident $item:ident: $imode:tt
[$(#[$imeta:meta])*]
[$( $var:ident: $typ:ty ),*]
{ from() $( $tail:tt )*}
) => {
$(#[$imeta])*
$(
impl From<$typ> for $name {
fn from($var: $typ) -> $name {
Expand All @@ -756,39 +758,45 @@ macro_rules! quick_error {
}
)*
quick_error!(FIND_FROM_IMPL
$name $item: $imode [$( $var:$typ ),*]
$name $item: $imode [$( #[$imeta] )*] [$( $var:$typ ),*]
{$( $tail )*});
};
(FIND_FROM_IMPL $name:ident $item:ident: UNIT
[$(#[$imeta:meta])*]
[ ]
{ from($ftyp:ty) $( $tail:tt )*}
) => {
$(#[$imeta])*
impl From<$ftyp> for $name {
fn from(_discarded_error: $ftyp) -> $name {
$name::$item
}
}
quick_error!(FIND_FROM_IMPL
$name $item: UNIT [ ]
$name $item: UNIT [$( #[$imeta] )*] [ ]
{$( $tail )*});
};
(FIND_FROM_IMPL $name:ident $item:ident: TUPLE
[$(#[$imeta:meta])*]
[$( $var:ident: $typ:ty ),*]
{ from($fvar:ident: $ftyp:ty) -> ($( $texpr:expr ),*) $( $tail:tt )*}
) => {
$(#[$imeta])*
impl From<$ftyp> for $name {
fn from($fvar: $ftyp) -> $name {
$name::$item($( $texpr ),*)
}
}
quick_error!(FIND_FROM_IMPL
$name $item: TUPLE [$( $var:$typ ),*]
$name $item: TUPLE [$( #[$imeta] )*] [$( $var:$typ ),*]
{ $($tail)* });
};
(FIND_FROM_IMPL $name:ident $item:ident: STRUCT
[$(#[$imeta:meta])*]
[$( $var:ident: $typ:ty ),*]
{ from($fvar:ident: $ftyp:ty) -> {$( $tvar:ident: $texpr:expr ),*} $( $tail:tt )*}
) => {
$(#[$imeta])*
impl From<$ftyp> for $name {
fn from($fvar: $ftyp) -> $name {
$name::$item {
Expand All @@ -797,29 +805,33 @@ macro_rules! quick_error {
}
}
quick_error!(FIND_FROM_IMPL
$name $item: STRUCT [$( $var:$typ ),*]
$name $item: STRUCT [$( #[$imeta] )*] [$( $var:$typ ),*]
{ $($tail)* });
};
(FIND_FROM_IMPL $name:ident $item:ident: $imode:tt
[$(#[$imeta:meta])*]
[$( $var:ident: $typ:ty ),*]
{ $t:tt $( $tail:tt )*}
) => {
quick_error!(FIND_FROM_IMPL
$name $item: $imode [$( $var:$typ ),*]
$name $item: $imode [$( #[$imeta] )*] [$( $var:$typ ),*]
{$( $tail )*}
);
};
(FIND_FROM_IMPL $name:ident $item:ident: $imode:tt
[$(#[$imeta:meta])*]
[$( $var:ident: $typ:ty ),*]
{ }
) => {
};
// ----------------------------- CONTEXT IMPL --------------------------
(FIND_CONTEXT_IMPL $name:ident $item:ident: TUPLE
[$(#[$imeta:meta])*]
[$( $var:ident: $typ:ty ),*]
{ context($cvar:ident: AsRef<$ctyp:ty>, $fvar:ident: $ftyp:ty)
-> ($( $texpr:expr ),*) $( $tail:tt )* }
) => {
$(#[$imeta])*
impl<T: AsRef<$ctyp>> From<$crate::Context<T, $ftyp>> for $name {
fn from(
$crate::Context($cvar, $fvar): $crate::Context<T, $ftyp>)
Expand All @@ -829,14 +841,16 @@ macro_rules! quick_error {
}
}
quick_error!(FIND_CONTEXT_IMPL
$name $item: TUPLE [$( $var:$typ ),*]
$name $item: TUPLE [$( #[$imeta] )*] [$( $var:$typ ),*]
{ $($tail)* });
};
(FIND_CONTEXT_IMPL $name:ident $item:ident: TUPLE
[$(#[$imeta:meta])*]
[$( $var:ident: $typ:ty ),*]
{ context($cvar:ident: $ctyp:ty, $fvar:ident: $ftyp:ty)
-> ($( $texpr:expr ),*) $( $tail:tt )* }
) => {
$(#[$imeta])*
impl<'a> From<$crate::Context<$ctyp, $ftyp>> for $name {
fn from(
$crate::Context($cvar, $fvar): $crate::Context<$ctyp, $ftyp>)
Expand All @@ -846,14 +860,16 @@ macro_rules! quick_error {
}
}
quick_error!(FIND_CONTEXT_IMPL
$name $item: TUPLE [$( $var:$typ ),*]
$name $item: TUPLE [$( #[$imeta] )*] [$( $var:$typ ),*]
{ $($tail)* });
};
(FIND_CONTEXT_IMPL $name:ident $item:ident: STRUCT
[$(#[$imeta:meta])*]
[$( $var:ident: $typ:ty ),*]
{ context($cvar:ident: AsRef<$ctyp:ty>, $fvar:ident: $ftyp:ty)
-> {$( $tvar:ident: $texpr:expr ),*} $( $tail:tt )* }
) => {
$(#[$imeta])*
impl<T: AsRef<$ctyp>> From<$crate::Context<T, $ftyp>> for $name {
fn from(
$crate::Context($cvar, $fvar): $crate::Context<$ctyp, $ftyp>)
Expand All @@ -865,14 +881,16 @@ macro_rules! quick_error {
}
}
quick_error!(FIND_CONTEXT_IMPL
$name $item: STRUCT [$( $var:$typ ),*]
$name $item: STRUCT [$( #[$imeta] )*] [$( $var:$typ ),*]
{ $($tail)* });
};
(FIND_CONTEXT_IMPL $name:ident $item:ident: STRUCT
[$(#[$imeta:meta])*]
[$( $var:ident: $typ:ty ),*]
{ context($cvar:ident: $ctyp:ty, $fvar:ident: $ftyp:ty)
-> {$( $tvar:ident: $texpr:expr ),*} $( $tail:tt )* }
) => {
$(#[$imeta])*
impl<'a> From<$crate::Context<$ctyp, $ftyp>> for $name {
fn from(
$crate::Context($cvar, $fvar): $crate::Context<$ctyp, $ftyp>)
Expand All @@ -884,19 +902,21 @@ macro_rules! quick_error {
}
}
quick_error!(FIND_CONTEXT_IMPL
$name $item: STRUCT [$( $var:$typ ),*]
$name $item: STRUCT [$( #[$imeta] )*] [$( $var:$typ ),*]
{ $($tail)* });
};
(FIND_CONTEXT_IMPL $name:ident $item:ident: $imode:tt
[$(#[$imeta:meta])*]
[$( $var:ident: $typ:ty ),*]
{ $t:tt $( $tail:tt )*}
) => {
quick_error!(FIND_CONTEXT_IMPL
$name $item: $imode [$( $var:$typ ),*]
$name $item: $imode [$( #[$imeta] )*] [$( $var:$typ ),*]
{$( $tail )*}
);
};
(FIND_CONTEXT_IMPL $name:ident $item:ident: $imode:tt
[$(#[$imeta:meta])*]
[$( $var:ident: $typ:ty ),*]
{ }
) => {
Expand Down