Simplify current codes with TryFromNum

This commit is contained in:
Jianfeng Jiang
2023-04-17 16:11:36 +08:00
committed by Tate, Hongliang Tian
parent 6ecc7dc557
commit 6cea03b871
16 changed files with 82 additions and 188 deletions

View File

@ -71,7 +71,9 @@ fn fn_body_tokens(value_name: &str, data_enum: &DataEnum, ident: Ident) -> Token
let statement = quote!(#value => ::core::result::Result::Ok(#ident::#vairant_ident),);
match_bodys.append_all(statement);
}
match_bodys.append_all(quote!(_ => core::result::Result::Err(::int_to_c_enum::TryFromIntError::InvalidValue),));
match_bodys.append_all(
quote!(_ => core::result::Result::Err(::int_to_c_enum::TryFromIntError::InvalidValue),),
);
let param = format_ident!("{}", value_name);
quote!(match #param {
#match_bodys

View File

@ -33,7 +33,7 @@
//! }
//! }
//! ```
//!
//!
#![no_std]
@ -44,4 +44,4 @@ pub enum TryFromIntError {
}
#[cfg(feature = "derive")]
pub use int_to_c_enum_derive::TryFromInt;
pub use int_to_c_enum_derive::TryFromInt;