| Crates.io | strongly |
| lib.rs | strongly |
| version | 0.1.1 |
| created_at | 2024-04-05 18:34:12.472943+00 |
| updated_at | 2024-04-16 18:13:30.178116+00 |
| description | A proc macro to create strongly-typed primitives |
| homepage | |
| repository | https://github.com/cloneable/strongly |
| max_upload_size | |
| id | 1197621 |
| size | 63,901 |
#[strongly::typed]A proc macro to create strongly-typed primitives.
[!CAUTION] Work in progress. Do not use yet. More details to follow.
Add the #[strongly::typed] attribute to your newtype struct to turn
it into a strongly-typed primitive. Supports all integers and floats, plus
bool and char.
#[strongly::typed]
struct MyType(u8);
The attribute will also add all nine possible default derives (Copy, Clone,
Default, etc.) and set #[repr(transparent)].
From/Into between inner and outer
types. Also add implementation of Borrow of all inner primitives except
floats. Provide const helper method to access inner primitive. Without this
there's no way to access the wrapped primitive (Except for mem::transmute or
via Display/FromStr, etc.).Serialize and Deserialize to and
from the representation of the primitive.Deref and DerefMut.#[strongly::typed(convert, serde)]
pub struct MyType(pub usize);
The types generated by this crate are meant to fill the gap between using an untyped primitive and a specialized newtype struct. They're meant to be used as drop-in replacements for the primitives while providing the same isolation as newtype structs.
The generated types implement all the traits and provide (almost) all the constants, functions and methods of the wrapped primitives. They are a very thin layer and will disappear during compilation.
Step trait is unstable. Instead, the macro generates helper methods to
create (strongly-typed) iterators.bools cannot be directly used as if condition expressions
nor can they be directly used in && and || (short-circuit) operations as
these operators are not implementable. (TODO: Offer Deref<Target=bool> via
feature for convenience.)std.