Crates.io | aggregate_derive |
lib.rs | aggregate_derive |
version | 0.3.3 |
source | src |
created_at | 2023-01-24 01:27:41.706715 |
updated_at | 2023-02-07 06:30:18.048047 |
description | Aggregate attributes of structs for runtime |
homepage | |
repository | https://github.com/voidentente/aggregate |
max_upload_size | |
id | 766363 |
size | 10,626 |
Access attributes of structs, enums, unions, and their fields using a simple Derive macro and without allocating.
Aggregate utilizes the power of macros, perfect hash functions, and lazy loading for extreme performance.
Amalgamate
s are singletons representing a struct/enum/union's
attribute structure that lie in shared static memory and can be accessed via
a type function call.
Aggregate works recursively by calling aggregate()
on nested structures
without limiting the types that can be used, and without runtime overhead
by simply linking to nested Amalgamate
s by reference.
Attributes are kept intact, which means that on access, they are
represented as syn::Attribute
s. However, parsing all attributes from tokens
can be costly and wasteful, which is why they are lazy-loaded and only parsed
when accessed.
By default, all features are enabled.
derive
re-exports aggregate_derive
.
impl
adds default implementations for common types like Option<T>
.
fmt
implements fmt::Debug
for Amalgamate
.
aggregate
is extremely simple to use.
In order to aggregate attributes of your struct/enum/union, simply derive it:
// The prelude is not required for derive,
// however in order to use `aggregate`,
// the trait must be in scope
use aggregate::prelude::*;
/// This attribute is paired with the type
#[derive(Aggregate)]
struct Config {
/// This attribute is paired with the field
switch: bool,
}
Aggregate supports nesting:
/// This attribute is paired with the type.
#[derive(Aggregate)]
struct ConfigFile {
/// This attribute is paired with the field
///
/// This field has an `inner`, which will
/// include the aggregation of `Config`
///
/// In order for `aggregate_derive` to notice
/// nested structures, you must mark the field
/// with the `#[aggregate]` attribute:
#[aggregate]
my_config: Config,
}
The #[aggregate]
attribute is not required on enum variants,
but is again required inside enum variant structs and tuples:
#[derive(Aggregate)]
enum MyEnum {
/// Variants are automatically included
VariantOne {
/// Fields must be marked
#[aggregate]
field_1: Inner,
},
/// Unnamed structs like this are also
/// supported; `aggregate` simply enumerates
/// the fields for representation
VariantTwo(#[aggregate] Inner),
}