#string #newtype #validation #normalization


Examples demonstrating usage of the aliri_braid crate

10 unstable releases (3 breaking)

0.4.0 May 26, 2023
0.3.1 Nov 2, 2022
0.2.4 Jul 21, 2022
0.2.3 Jun 15, 2022
0.1.9 Jul 8, 2021

#1674 in Rust patterns

Download history 17/week @ 2023-10-28 3/week @ 2023-11-04 2/week @ 2023-11-11 11/week @ 2023-11-18 32/week @ 2023-11-25 20/week @ 2023-12-02 10/week @ 2023-12-16 30/week @ 2023-12-23 6/week @ 2024-01-13 7/week @ 2024-01-20 41/week @ 2024-01-27 35/week @ 2024-02-10

89 downloads per month


268 lines


Build Status

Improve and strengthen your strings

Strongly-typed APIs reduce errors and confusion over passing around un-typed strings. Braid helps in that endeavor by making it painless to create wrappers around your string values, ensuring that you use them in the right way every time.

Examples of the documentation and implementations provided for braids are available below and in the aliri_braid_examples crate documentation.


A braid is created by attaching #[braid] to a struct definition. The macro will take care of automatically updating the representation of the struct to wrap a string and generate the borrowed form of the strong type.

use aliri_braid::braid;

pub struct DatabaseName;

Braids of custom string types are also supported, so long as they implement a set of expected traits. If not specified, the type named String in the current namespace will be used.

use aliri_braid::braid;
use compact_str::CompactString as String;

pub struct UserId;

Once created, braids can be passed around as strongly-typed, immutable strings.

fn take_strong_string(n: DatabaseName) {}
fn borrow_strong_string(n: &DatabaseNameRef) {}

let owned = DatabaseName::new(String::from("mongo"));

A braid can also be untyped for use in stringly-typed interfaces.

fn take_raw_string(s: String) {}
fn borrow_raw_str(s: &str) {}

let owned = DatabaseName::new(String::from("mongo"));

For more information, see the documentation on docs.rs.


~37K SLoC