amplify 1.2.0

Amplifying Rust language capabilities: multiple generic trait implementations, type wrappers, derive macros
Documentation

Rust Amplify Library

crates.io Build Tests Lints codecov MIT licensed

Amplifying Rust language capabilities: multiple generic trait implementations, type wrappers, derive macros.

Minimum supported rust compiler version (MSRV): 1.41.1

Main features

Derive macros

  • Display
  • From
  • Error
  • Getters
  • AsAny

A sample of what can be done with the macros:

#[derive(From, Error, Display, Debug)]
#[display(doc_comments)]
pub enum Error {
    // You can specify multiple conversions with separate attributes
    #[from(::std::io::Error)]
    #[from(IoError)]
    /// Generic I/O error
    Io,

    #[from]
    // This produces error description referencing debug representation
    // of the internal error type
    /// Formatting error: {_0:}
    Format(::std::fmt::Error),

    #[from]
    /// Some complex error, here are details: {details}
    WithFields { details: ::std::str::Utf8Error },

    #[display(LowerHex)]
    MultipleFields {
        // ...and you can also covert error type
        #[from(IoErrorUnit)]
        // rest of parameters must implement `Default`
        io: IoError,

        #[display(ToHex::to_hex)]
        details: String,
    },
}

See more in amplify_derive crate README.

Macros

  • s! for fast &str -> String conversions
  • Collection-generating macros:
    • map! & bmap! for a rappid HashMap and BTreeMap creation
    • set! & bset! for a rappid HashSet and BTreeSet creation
    • list! for LinkedList

Generics

Library proposes generic implementation strategies, which allow multiple generic trait implementations. See src/strategy.rs mod for the details.

Wapper type

TODO: write description

Build

rustup install nightly
rustup default nightly
cargo build --all
cargo test