| Crates.io | attr-bounds |
| lib.rs | attr-bounds |
| version | 0.1.0 |
| created_at | 2024-06-12 18:04:52.719634+00 |
| updated_at | 2024-06-12 18:04:52.719634+00 |
| description | An attribute macro to apply bounds to items. |
| homepage | |
| repository | https://github.com/mtshr/attr-bounds |
| max_upload_size | |
| id | 1269835 |
| size | 26,938 |
An attribute macro to stipulate bounds.
The attribute applies bounds to structs, enums, unions, traits, fns, and impl blocks.
use attr_bounds::bounds;
#[bounds(T: Copy)]
pub struct Wrapper<T>(T);
let var = Wrapper(42);
Basically, the attribute is designed to be used for conditional compilation and otherwise you will not need the attribute.
use attr_bounds::bounds;
#[cfg(feature = "unstable_feature_a")]
pub trait UnstableA {}
#[cfg(feature = "unstable_feature_b")]
pub trait UnstableB {}
#[cfg_attr(feature = "unstable_feature_a", bounds(Self: UnstableA))]
#[cfg_attr(feature = "unstable_feature_b", bounds(Self: UnstableB))]
pub trait Trait {}
#[cfg(feature = "unstable_feature_a")]
impl UnstableA for () {}
#[cfg(feature = "unstable_feature_b")]
impl UnstableB for () {}
impl Trait for () {}