shorter-bounds

Crates.ioshorter-bounds
lib.rsshorter-bounds
version
sourcesrc
created_at2024-10-04 12:20:22.912645
updated_at2024-10-04 12:31:24.38309
descriptionWrite shorter bounds with a trait alias macro.
homepage
repositoryhttps://github.com/nanocryk/shorter-bounds
max_upload_size
id1396456
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
(nanocryk)

documentation

README

shorter-bounds

shorter-bounds crate shorter-bounds documentation

Provides a macro to easily define a trait alias, implemented automatically for all types that implement the super traits. It supports both supertrait bounds (trait Foo : Bounds) and type parameters bounds (trait Foo<T: (Bounds)>). The latter requires parenthesis around the bounds to easility parse them and support any valid Rust bound syntax.

Since Rust 1.79, you can add bounds to traits associated types, which will also imply that bound when the trait alias is used (contrary to using a where clause). This allows to define powerful trait aliases that avoids repeating many <Foo as Bar>::Baz : Traits.

Syntax

shorter_bounds::alias!(
    pub // Optional
    trait
    MyTraitAlias
    // Can be followed by type parameters
    <
        Foo,
        // Type paramter can have bounds, but they must be wrapped inside parenthesis
        Bar: (Clone + Iterator<Item: Clone>),
    >
    :
    // List of traits being aliased
    Clone +
        Iterator<Item = (Foo, Bar)>
);

Exemple

shorter_bounds::alias!(pub trait IterableOfClonable: Iterator<Item: Clone>);
fn exemple(iter: impl IterableOfClonable) {
    for x in iter {
        let _ = x.clone();
    }
}
exemple([42, 63].into_iter());
Commit count: 4

cargo fmt