Skip to content

Commit

Permalink
Add some usage information
Browse files Browse the repository at this point in the history
  • Loading branch information
cloneable committed Apr 12, 2024
1 parent 2c4234d commit 504e8cc
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
# strongly
# strongly::typed

[WIP] A proc macro to create strongly-typed primitives.

## Usage

Add the `#[strongly::typed(<primitive>)]` attribute to your unit struct to turn
it into a strongly-typed primitive. Supports all integers and floats, plus
`bool` and `char`.

```rust
#[strongly::typed(u8)]
pub struct SpecialInt;
```

The attribute will also add all nine possible default derives (`Copy`, `Clone`,
`Default`, etc.) and set `#[repr(transparent)]`.

## Features

* Default: `std`
* `std`: Doesn't do anything at the moment.
* `serde`: Generate implementations of `Serialize` and `Deserialize` to and from
the representation of the primitive.

## Caveats

* It's not possible to loop over strongly-typed integer ranges
because the `Step` trait is unstable. Instead, the macro generates
helper methods to create (strongly-typed) iterators.
* It's not possible to loop over strongly-typed integer ranges because the
`Step` trait is unstable. Instead, the macro generates helper methods to
create (strongly-typed) iterators.
* Strongly-typed `bool`s cannot be directly used as `if` condition expressions
nor can they be directly used in `&&` and `||` operations as these are not
implementable. (TODO: Offer `Deref<Target=bool>` via feature.)

0 comments on commit 504e8cc

Please sign in to comment.