Welcome to contained
, a collection of macros and other utilities designed to facilitate the creation and manipulation of so-called wrapper types in Rust. Here, a wrapper type is essentially any object capable of implementing the #[repr(transparent)]
attribute, such as newtypes, tuple structs, and single-field enums.
Before you start using contained
, make sure to add it as a dependency in your Cargo.toml
file. You can do this by adding the following lines:
[dependencies.contained]
features = [
"derive",
]
version = "0.2.x"
For more detailed examples, please visit the examples directory in the repository. Below are some brief examples highlighting certain features of the library.
use contained::Wrapper;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Wrapper)]
pub struct A<T>(T);
fn main() {
let mut a = A::new(1).map(|x| x + 100);
assert_eq!(a.get(), &101);
a.set(202);
assert_eq!(a.get_mut(), &mut 202);
}
use contained::fmt_wrapper;
#[derive(Clone, Copy, Eq, Hash, PartialEq, PartialOrd)]
pub struct A<T>(T);
#[derive(Clone, Copy, Eq, Hash, PartialEq, PartialOrd)]
pub struct B<T> {
pub value: T,
}
fmt_wrapper! {
impl A<T> {
Debug,
Display,
LowerHex,
UpperHex,
LowerExp,
UpperExp,
Binary,
Octal,
Pointer,
}
}
fmt_wrapper! {
impl B<T>.value {
Debug,
Display,
LowerHex,
UpperHex,
LowerExp,
UpperExp,
Binary,
Octal,
Pointer,
}
}
fn main() {
let a = A::new(255);
let b = B { value: 255 };
println!("A: {a:X}, B: {b:X}");
}
To get started with contained
, you can check out the QUICKSTART.md file, which provides a step-by-step guide on how to set up your development environment and start using the library.
Licensed under the Apache License, Version 2.0
Contributions are welcome, however, ensure that you have read the CONTRIBUTING.md file before submitting a pull request.
For any security vulnerabilities, please refer to the SECURITY.md file for guidance on how to report them.