6 releases
| 0.3.2 | Nov 2, 2025 |
|---|---|
| 0.3.1 | Oct 23, 2025 |
| 0.2.0 | Oct 7, 2025 |
| 0.1.1 | Aug 4, 2025 |
| 0.1.0 | May 27, 2025 |
#397 in Rust patterns
2,083 downloads per month
Used in 3 crates
64KB
1K
SLoC
wrapper-lite
The new type idiom gives compile time guarantees that the right type of value is supplied to a program.
This crate provides a simple macro for you to create a wrapper over any type.
Notable changes since v0.3.0
-
Starting from v0.3.1, the complex usage now accept any inner field name (but must be the first one).
wrapper_lite::wrapper!( #[wrapper_impl(AsRef<str>)] pub struct TestWrapperComplex { value: String, // <-- can be any name now, not necessarily "inner" _marker: ::core::marker::PhantomData<()>, } ); -
In v0.3.1, we introduce
#[repr(align(cache))]attribute for the wrapper struct.wrapper_lite::wrapper!( #[repr(align(cache))] pub struct AlignedWrapper(u8); );See the docs for usage details.
Migrate from v0.2.X
-
The macro now only accepts valid Rust struct syntax.
wrapper_lite::wrapper!( pub struct TestWrapper1(u8); // <-- note the semicolon, now it's required );wrapper_lite::wrapper!( pub struct TestWrapper2 { inner: u8, } ); -
When there's no default value specified, we cannot implement the
Fromtrait for the wrapper type, and now it's a hard error.wrapper_lite::wrapper!( #[wrapper_impl(From)] pub struct TestWrapperComplex<'a, 'b> { inner: String, _a: ::core::marker::PhantomData<&'a ()>, _b: ::core::marker::PhantomData<&'b ()>, } );
Migrate from v0.1.X
To make cargo-fmt happy, starting from v0.2.0, the following usage which is not a valid Rust struct syntax is no longer accepted.
wrapper_lite::wrapper!(
pub ExampleWrapper(u8)
);
Instead:
wrapper_lite::wrapper!(
pub struct ExampleWrapper(u8);
);
Now we can format the macro content with cargo fmt!
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.