Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
yunjhongwu committed Feb 16, 2024
1 parent ba5de87 commit bd955f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ println!("{}", timestamp); // Timestamp(1701620628123456789)
- **Derive trait `StrongType`:** Create a named strong type.
- The macro automatically implement common traits like `Clone`, `Debug`, `Default`, `PartialEq`, `PartialOrd`, `Send`, and `Sync`. It also implements `Display` by default, unless overridden by the custom_display attribute.
- Conditionally, based on the underlying data type, traits like `Copy`, `Eq`, `Ord`, `Hash` may also be implemented. For primitive data types like `i32` or `bool`, these additional traits will be automatically included.
- Numeric types, both integer and floating-point, also implement constants `MIN`, `MAX`, and `ZERO`. Additionally, for floating-point types, `NAN` is implemented.
- Numeric types, both integer and floating-point, also implement constants `MIN`, `MAX`, `INFINITY`, `NEG_INFINITY`, and `ZERO`. Additionally, for floating-point types, `NAN` is implemented.

- **Attributes:**
- Adding the following attributes to `#[strong_type(...)]` allows for additional features:
Expand Down Expand Up @@ -160,4 +160,4 @@ struct Cash(Dollar);
#[derive(StrongType)]
#[strong_type(underlying = i32)]
struct Coin(Cash);
```
```
12 changes: 12 additions & 0 deletions strong-type/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
//! This crate offers a derive macro for crafting strong types in Rust, where a strong type
//! encapsulates a primitive type, providing a distinct, purpose-specific identity. This pattern
//! is useful for creating distinct types for distinct purposes. Several macro attributes are
//! provided to customize the strong type, such as directly implementing arithmetic operators of
//! the underlying primitive type,
//!
//! See the [crate documentation](https://crates.io/crates/strong-type) for more details and examples.
//!
use std::fmt::Debug;

/// Derive macro to create strong types in Rust.
pub use strong_type_derive::StrongType;

/// Trait for strong types to obtain the associated underlying type and primitive type.
pub trait StrongType: Debug + PartialEq + PartialOrd + Clone + Default + Send + Sync {
type UnderlyingType: Default;
type PrimitiveType;
Expand Down

0 comments on commit bd955f3

Please sign in to comment.