Crate amplify

source ·
Expand description

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

Minimum supported rust compiler version (MSRV): 1.46 (stable channel)

Re-exports

pub extern crate ascii;
pub use crate::strategy::Holder;

Modules

Confinement puts a constrain on the number of elements within a collection.
Types for building flag-based APIs and functionality
Hex encoding and decoding
Custom-sized numeric types
This is a trick for rust compiler helping to distinguish types implementing mutually-exclusive traits (required until negative trait impls will be there) Implemented after concept by Martin Habovštiak martin.habovstiak@gmail.com

Macros

Macro for creating std::collections::BTreeMap in the same manner as vec! is used for Vec:
Macro for creating std::collections::BTreeSet in the same manner as vec! is used for Vec:
Helper macro to construct confined BTreeMap of a given type
Helper macro to construct confined BTreeSet of a given type
Helper macro to construct confined HashMap of a given type
Helper macro to construct confined HashSet of a given type
Helper macro to construct confined vector of a given type
Shorthand for Default::default()
Shorthand for Dumb::dumb()
This macro allows more semantically-clear code (which can be used especially with structure initialization), indicating that instead of type value we are generating empty collection types
Macro for creating std::collections::LinkedList in the same manner as vec! is used for Vec:
Macro for creating std::collections::HashMap in the same manner as vec! is used for Vec:
This macro allows more semantically-clear code (which can be used especially with structure initialization), indicating that instead of type value we are generating no value at all (empty collection or data structure filled with information indicating absence of data)
Macro for quick & simple &str -> String conversion:
Macro for creating std::collections::HashSet in the same manner as vec! is used for Vec:
Helper macro to construct confined BTreeMap of a SmallOrdMap type
Helper macro to construct confined BTreeSet of a SmallOrdSet type
Helper macro to construct confined HashMap of a SmallHashMap type
Helper macro to construct confined string of a SmallString type
Helper macro to construct confined HashSet of a SmallHashSet type
Helper macro to construct confined vector of a SmallVec type
Helper macro to construct confined BTreeMap of a TinyOrdMap type
Helper macro to construct confined BTreeSet of a TinyOrdSet type
Helper macro to construct confined HashMap of a TinyHashMap type
Helper macro to construct confined string of a TinyString type
Helper macro to construct confined HashSet of a TinyHashSet type
Helper macro to construct confined vector of a TinyVec type
This macro allows more semantically-clear code (which can be used especially with structure initialization), indicating that instead of type value we are generating zero values (int types or byte slices filled with zeros)

Structs

Wrapper type for all fixed arrays implementing many important traits, so types based on it can simply derive their implementations.
Errors with io::ErrorKind::UnexpectedEof on [Read] and [Write] operations if the LIM is reached.
Copyable & cloneable I/O error type represented by the error kind function.
A simple way to count bytes written through io::Write.

Traits

Trait AsAny allows simple conversion of any type into a generic “thick” pointer &dyn Any (see ::core::any::Any), that can be later converted back to the original type with a graceful failing for all other conversions. For simple conversions it is recommended to use #[derive(AsAny)] macro from amplify_derive crate (see amplify_derive::AsAny).
Used as an alternative to default for test and prototyping purposes, when a type can’t have a default value, but you need to generate some dumb data.
Trait for splittable streams and other types, which can be separated into some two types (JoinSplit::A, JoinSplit::B), like a reader and writer streams.
Trait which does a blanket implementation for all types wrapping Arrays
Trait defining wrapped types (“newtypes” in rust terminology). Wrapped types are used for allowing implemeting foreign traits to foreign types: https://doc.rust-lang.org/stable/rust-by-example/generics/new_types.html
Trait allowing mutable reference borrowing for the wrapped inner type.

Type Definitions

Wrapper type for all slice-based 128-bit types implementing many important traits, so types based on it can simply derive their implementations.
Wrapper type for all slice-based 256-bit types implementing many important traits, so types based on it can simply derive their implementations.
Wrapper type for all slice-based 512-bit types implementing many important traits, so types based on it can simply derive their implementations.

Derive Macros

Trait amplify::AsAny allows simple conversion of any type into a generic “thick” pointer &dyn Any (see ::core::any::Any), that can be later converted back to the original type with a graceful failing for all other conversions. AsAny derive macro allows to implement this trait for arbitrary time without much hussle:
Usage
Error derive macro works to the full extend only when other derive macros are used. With #[derive(Display)] and [display(doc_comments)] it uses doc comments for generating error descriptions; with #[derive(From)] it may automatically implement transofrations from other error types.
Implements From trait for the whole entity and/or its separate fields. Works well with #[derive(Error)] and, in many cases may require Default implementation (for details, pls see Examples below)
Derives getter methods for structures. The return type and naming of the methods depends on the provided attribute arguments.
Creates rust new type wrapping existing type. Can be used in structures containing multiple named or unnamed fields; in this case the field you’d like to wrap should be marked with #[wrap] attribute; otherwise the first field is assumed to be the wrapped one.
Derives WrapperMut and allows deriving other traits accessing the wrapped type which require mutable access to the inner type. Requires that the type already implements amplify::Wrapper.