Skip to content

Commit

Permalink
update enum docs
Browse files Browse the repository at this point in the history
  • Loading branch information
borngraced committed Jul 8, 2024
1 parent f772310 commit 6a4bec5
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions mm2src/derives/enum_derives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,42 @@ const ENUM_VARIANT_LIST_IDENT: &str = "EnumVariantList";

/// Implements `From<Inner>` trait for the given enumeration.
///
/// # Usage
///
/// ### USAGE:
/// ```rust
/// use enum_derives::EnumFromInner;
/// use enum_from_variant::EnumFromVariant;
/// use derive_more::Display;
///
/// #[derive(EnumFromInner)]
/// enum FooBar {
/// #[from_inner]
/// Foo(i32),
/// #[from_inner]
/// Bar(&'static str),
/// #[derive(Debug, EnumFromVariant)]
/// pub enum MainError {
/// #[enum_from_variant("NetworkError")]
/// Network(String),
/// #[enum_from_variant("DatabaseError")]
/// Database(DatabaseError),
/// }
///
/// #[derive(Debug, Display)]
/// pub enum NetworkError {
/// Timeout(String),
///}
///
/// #[derive(Debug, Display)]
/// pub enum DatabaseError {
/// ConnectionFailed(String),
/// }
///
/// match FooBar::from(10i32) {
/// FooBar::Foo(10) => (),
/// _ => panic!(),
/// fn network_request() -> Result<(), MainError> {
/// Err(NetworkError::Timeout("Network timeout".to_string()).into())
/// }
/// match FooBar::from("Hello, world") {
/// FooBar::Bar("Hello, world") => (),
/// _ => panic!(),
///
/// fn main() {
/// match network_request() {
/// Ok(_) => println!("Request succeeded"),
/// Err(e) => println!("Error: {:?}", e),
/// }
/// }
/// ```
///

#[proc_macro_derive(EnumFromInner, attributes(from_inner))]
pub fn enum_from_inner(input: TokenStream) -> TokenStream {
let input: DeriveInput = parse_macro_input!(input);
Expand Down

0 comments on commit 6a4bec5

Please sign in to comment.