6 releases (3 breaking)
✓ Uses Rust 2018 edition
|new 0.3.0-alpha||Mar 25, 2020|
|0.2.2||Dec 6, 2019|
|0.2.1||Nov 28, 2019|
|0.1.1||Nov 8, 2019|
|0.0.0||Oct 14, 2019|
#115 in Rust patterns
79 downloads per month
This library provides field accessor traits,and emulation of structural types.
These are some of the features this library provides:
StructuralExtextension trait,which defines the main methods to access fields, so long as the type implements the accessor traits for those fields.
structural_aliasmacro, to declare trait aliases for accessor traits, using field-in-trait syntax.
The way that this library emulates structural types is by using traits as bounds or trait objects.
By default all structural types are open, structs and enums can have more variants and or fields than are required.
The only exception to this is exhaustive enums,
in which the variant count and names must match exactly,
this is useful for exhaustive matching of variants (in the
For examples you can look at the examples section of the documentation for the root module of the structural crate
The changelog is in the "Changelog.md" file.
None right now.
structural in no_std contexts disable the default-feature.
This crate has few items that require the
std crate (instead of core).
The "std" and "alloc" features are enabled by default so that users that are not
aware of the
alloc crates don't have to pass a feature to enable
These are the cargo features in structural:
std: Enables std support,this is enabled by default.
alloc: Enables alloc crate support,this is enabled by default.
specialization: Enables specialization inside structural,without enabling the nightly feature flag. This is for the case that specialization is stabilized after the last update to this library.
nightly_specialization: Enables specialization inside structural, requires nightly because it enables the nightly feature.
impl_fields: This allows using
field_name: impl Foofields in the
structural_aliasmacro, which as of 2020-03-21 requires the
associated_type_boundsRust nightly feature.
If this doesn't work,try using the "nightly_impl_fields" feature in Rust nightly instead.
nightly_impl_fieldsEquivalent to the
impl_fieldsfeature, as well as enabling the
associated_type_boundsnightly features required for using the feature as of 2020-03-21.
use_const_str: Changes the internal implementation of
TStr(the type level string type) to use a
&'static strconst parameter instead of types.
Use this if const generics (eg:
struct Foo<const S: &'static str>;) are usable on stable.
nightly_use_const_str: Equivalent to the
impl_fieldsfeature, which also enables the nightly Rust features required for const generics as of 2020-03-21.
disable_const_str: Disables const generics, useful if other crates enabling const generics causes internal errors in this Rust version.
Specialization is used inside
structural for performance reasons.
There are no benchmarks comparing when specialization is enabled and disabled yet.
This crate support Rust back to 1.40, and uses a build script to automatically enable features from newer versions.
Licensed under either of Apache License, Version 2.0 or MIT license at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Structural by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.