Crates.io | rvstruct |
lib.rs | rvstruct |
version | 0.3.2 |
source | src |
created_at | 2020-06-18 18:01:37.132173 |
updated_at | 2022-12-11 12:58:36.465804 |
description | A helper macros implementation for Value Classes in Rust |
homepage | https://github.com/abdolence/rust-value-struct |
repository | https://github.com/abdolence/rust-value-struct |
max_upload_size | |
id | 255425 |
size | 4,207 |
A very simple derive macros to support strong type system and the newtype pattern. Newtypes are a zero-cost abstraction: they introduce a new, distinct name for an existing type, with no runtime overhead when converting between the two types. This is a similar approach to Haskell's newtype keyword.
For example:
#[derive(ValueStruct)]
struct UserId(String);
let uid : UserId = "my-uid".into();
ValueStruct
generates for you:
std::convert::From<>
instances automatically to help you to create your structs.ValueStruct::value()
function implementation to access your field directly without using .0.There are different behaviour for different field types:
std::string::String
it generates From<String>
, From<&String>
, From<&str>
Add this to your Cargo.toml
:
[dependencies]
rvstruct = "0.3"
// Import it
use rvstruct::ValueStruct;
// And use it on your structs
#[derive(ValueStruct)]
struct UserId(String);
Apache Software License (ASL)
Abdulla Abdurakhmanov