Skip to content
Snippets Groups Projects
Commit 5e4bc7c9 authored by Bastian Köcher's avatar Bastian Köcher Committed by GitHub
Browse files

Implement `TryInto` for outer events (#3549)

* Implement `TryInto` for outer events

* Remove invalid comment

* Fix compilation
parent c284ca21
Branches
No related merge requests found
......@@ -452,31 +452,44 @@ macro_rules! impl_outer_event {
$( $module_name:ident::Event $( <$generic_param:ident> )? $( { $generic_instance:ident } )?, )*;
) => {
$crate::paste::item! {
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
#[derive(Clone, PartialEq, Eq, $crate::codec::Encode, $crate::codec::Decode)]
#[cfg_attr(feature = "std", derive(Debug))]
$(#[$attr])*
#[allow(non_camel_case_types)]
pub enum $name {
system($system::Event),
$(
[< $module_name $(_ $generic_instance )? >](
$module_name::Event < $( $generic_param )? $(, $module_name::$generic_instance )? >
),
)*
}
impl From<$system::Event> for $name {
fn from(x: $system::Event) -> Self {
$name::system(x)
#[derive(Clone, PartialEq, Eq, $crate::codec::Encode, $crate::codec::Decode)]
#[cfg_attr(feature = "std", derive(Debug))]
$(#[$attr])*
#[allow(non_camel_case_types)]
pub enum $name {
system($system::Event),
$(
[< $module_name $(_ $generic_instance )? >](
$module_name::Event < $( $generic_param )? $(, $module_name::$generic_instance )? >
),
)*
}
}
$(
impl From<$module_name::Event < $( $generic_param, )? $( $module_name::$generic_instance )? >> for $name {
fn from(x: $module_name::Event < $( $generic_param, )? $( $module_name::$generic_instance )? >) -> Self {
$name::[< $module_name $(_ $generic_instance )? >](x)
impl From<$system::Event> for $name {
fn from(x: $system::Event) -> Self {
$name::system(x)
}
}
)*
$(
impl From<$module_name::Event < $( $generic_param, )? $( $module_name::$generic_instance )? >> for $name {
fn from(x: $module_name::Event < $( $generic_param, )? $( $module_name::$generic_instance )? >) -> Self {
$name::[< $module_name $(_ $generic_instance )? >](x)
}
}
impl $crate::rstd::convert::TryInto<
$module_name::Event < $( $generic_param, )? $( $module_name::$generic_instance )? >
> for $name {
type Error = ();
fn try_into(self) -> $crate::rstd::result::Result<
$module_name::Event < $( $generic_param, )? $( $module_name::$generic_instance )? >, Self::Error
> {
match self {
Self::[< $module_name $(_ $generic_instance )? >](evt) => Ok(evt),
_ => Err(()),
}
}
}
)*
}
$crate::__impl_outer_event_json_metadata!(
$runtime;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment