Search

Lib.rs

› Rust patterns
#transparent-wrapper #wrapper #macro

no-std contained

contained works to provide several macros and interface for transparent wrapper types in Rust

by Joe McCain III

  • Install
  • API reference
  • GitHub repo (fl03)

10 releases

Uses new Rust 2024

0.2.4 Jan 20, 2026
0.2.3 Dec 27, 2025
0.2.2 Sep 9, 2025
0.1.4 Apr 15, 2023
0.1.1 Jun 21, 2022

#524 in Rust patterns

Download history 84/week @ 2026-01-15 3/week @ 2026-01-22 53/week @ 2026-01-29 62/week @ 2026-02-05 31/week @ 2026-02-12 21/week @ 2026-02-19 47/week @ 2026-02-26 64/week @ 2026-03-05 82/week @ 2026-03-12 4/week @ 2026-03-26 18/week @ 2026-04-02 6/week @ 2026-04-09 64/week @ 2026-04-16 90/week @ 2026-04-23 115/week @ 2026-04-30

278 downloads per month
Used in 37 crates (11 directly)

Apache-2.0

36KB
307 lines

contained

crates.io docs.rs GitHub License


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.

Usage

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"

Examples

For more detailed examples, please visit the examples directory in the repository. Below are some brief examples highlighting certain features of the library.

Example 1: Using the Wrapper derive macro

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);
}

Example 2: Uisng the fmt_wrapper macro

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}");
}

Getting Started

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.

License

Licensed under the Apache License, Version 2.0

Contribution

Contributions are welcome, however, ensure that you have read the CONTRIBUTING.md file before submitting a pull request.

Security

For any security vulnerabilities, please refer to the SECURITY.md file for guidance on how to report them.

Dependencies

~0.2–3MB
~60K SLoC

  • contained-core
  • derive? nightly? contained-derive
  • macros? nightly? contained-macros
  • build build.rs
  • dev criterion 0.8+plotters

Other features

  • alloc
  • complex
  • full
  • hashbrown
  • json
  • rand
  • rayon
  • rng
  • serde
  • serde_json
  • std
  • wasi
  • wasm
  • wasm_bindgen
Related: contained-core, contained-derive, contained-macros, contained-music, contained-net, contained-turing, contained-actors
See also: tdms, sorted_array, emutil, deluxe, derive-enum-all-values, turbomcp-macros, case_iterable, enumcapsulate-macros, charmed-bubbletea-macros, deluxe-macros, konfik_derive

Lib.rs is an unofficial list of Rust/Cargo crates, created by kornelski. It contains data from multiple sources, including heuristics, and manually curated data. Content of this page is not necessarily endorsed by the authors of the crate. This site is not affiliated with nor endorsed by the Rust Project. If something is missing or incorrect, please file a bug.