From bd955f3c9c447791397dddafdf16560ceecea840 Mon Sep 17 00:00:00 2001 From: Yun-Jhong Wu Date: Fri, 16 Feb 2024 17:35:14 -0600 Subject: [PATCH] Update docs --- README.md | 4 ++-- strong-type/src/lib.rs | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7cc9d7e..01ce300 100644 --- a/README.md +++ b/README.md @@ -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: @@ -160,4 +160,4 @@ struct Cash(Dollar); #[derive(StrongType)] #[strong_type(underlying = i32)] struct Coin(Cash); -``` \ No newline at end of file +``` diff --git a/strong-type/src/lib.rs b/strong-type/src/lib.rs index 384db6b..13800dd 100644 --- a/strong-type/src/lib.rs +++ b/strong-type/src/lib.rs @@ -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;