strong-type-0.1.0 has been yanked.
strong-type
strong-type is a Rust crate providing macros to create strongly typed and named values. It simplifies the process of defining types that are distinct at the type level but share underlying data structures.
use StrongType;
;
let timestamp = Timestamp;
println!; // Timestamp(1701620628123456789)
Features
StrongType: Create a named strong type.StrongNumericType: ExtendStrongTypewith arithmetic operations.custom_display: Allow users to manually implementDisplayinstead of using the default display format.
Supported underlying types:
- Both
StrongTypeandStrongNumericType:i8,i16,i32,i64,i128,isizeu8,u16,u32,u64,u128,usizef32,f64
- Only
StrongType:boolcharString
Examples
Create a named strong type:
use StrongType;
;
let _ = Tag;
let tag = new;
let tag: Tag = "dev".into;
Strong type:
use StrongType;
use Any;
;
;
let x = Second;
let y = Second;
let z = Minute;
assert_eq!; // Same type: Second
assert_ne!; // Different type: Second versus Minute
Named type with arithmetic operations:
use StrongNumericType;
;
let x = Second;
let y = Second;
assert_eq!;
assert_eq!;
assert!;
assert!;
assert_eq!;
Named type with custom_display:
use StrongNumericType;
;
println!; // "Second(2.72)"
println!; // "Second { value: 2.718281828459045 }"