Skip to content

Commit

Permalink
Expand README a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
cloneable committed Apr 16, 2024
1 parent e192623 commit 79a8f92
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resolver = "2"

[package]
name = "strongly"
version = "0.1.0"
version = "0.1.1"
description = "A proc macro to create strongly-typed primitives"
authors = ["Folke <[email protected]>"]
license = "MIT OR Apache-2.0"
Expand Down
43 changes: 32 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ it into a strongly-typed primitive. Supports all integers and floats, plus
`bool` and `char`.

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

The attribute will also add all nine possible default derives (`Copy`, `Clone`,
Expand All @@ -23,22 +23,43 @@ The attribute will also add all nine possible default derives (`Copy`, `Clone`,

* __convert__: Generate implemetations of `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.
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.).
* __serde__: Generate implementations of `Serialize` and `Deserialize` to and
from the representation of the primitive.
* __deref__: Generate implementations of `Deref` and `DerefMut`.
* __serde__: Generate implementations of `Serialize` and `Deserialize` to and from
the representation of the primitive.

## Features
```rust
#[strongly::typed(convert, serde)]
pub struct MyType(pub usize);
```

* Default: __std__
* __std__: Doesn't do anything at the moment. None of the generated code requires
`std`.
## Purpose

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.

## 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.
* 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.)
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.)
* Doc comments are largely missing, except for trait impls.
(TODO: Generate links to doc comments of primitives.)

## Crate Features

* Default: __std__
* __std__: Doesn't do anything at the moment. None of the generated code requires
`std`.
2 changes: 1 addition & 1 deletion tests/base.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod types;
pub mod types;

macro_rules! tests {
( $($inner:ident)+ ) => {
Expand Down

0 comments on commit 79a8f92

Please sign in to comment.