#custom #slice #string #validation


Helper macros to implement std traits for custom validated slice types

3 unstable releases

0.2.0 Oct 25, 2019
0.1.1 Oct 22, 2019
0.1.0 Sep 25, 2019

#2603 in Rust patterns

Download history 29/week @ 2023-01-27 37/week @ 2023-02-03 31/week @ 2023-02-10 27/week @ 2023-02-17 24/week @ 2023-02-24 24/week @ 2023-03-03 18/week @ 2023-03-10 23/week @ 2023-03-17 21/week @ 2023-03-24 21/week @ 2023-03-31 30/week @ 2023-04-07 21/week @ 2023-04-14 25/week @ 2023-04-21 25/week @ 2023-04-28 31/week @ 2023-05-05 24/week @ 2023-05-12

108 downloads per month


1.5K SLoC


Build Status Latest version Documentation Minimum rustc version: 1.37

Helper macros to implement std traits for custom validated slice types in Rust.

See tests/ascii_str.rs and tests/plain_str.rs for example. These examples defines custom string types and implement basic std traits for them by this crate.

Custom slice

To define opaque type aliases for data with specific characteristics, you may want to define custom slice types and vector types. For example:

  • String with only ASCII characters.
  • String which is a valid URI.
  • Escaped HTML and unescaped HTML.
  • String with case-insensitive comparison by PartialEq and PartialOrd).
  • Non-empty array.
  • Sorted array.

However, primitive types [T] and str have many trait impls, and custom array types might be non-user-friendly without such trait impls. (For example, if you want ASCII string &AsciiStr, you may also want Default for &AsciiStr, std::convert::TryFrom<&str> for &AsciiStr, PartialEq<str> for &AsciiStr, PartialOrd<AsciiStr> for Cow<'_, AsciiStr>, std::fmt::Display for AsciiStr`, etc.)

validated-slice helps users to automatically implement these traits common for array and string with less boilerplates.

Current status

This crate is at an early stage, and experimental. Breaking changes would be introduced for syntax and features.

This crate follows semver, so you can check crate version to know breaking change.


  • nostd support
    • See docs of the macros for detail.


For desired features without detailed ideas, see TODO.md.


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps