reliakit-primitives
Type-safe primitives for constrained and reliability-oriented Rust values.
reliakit-primitives provides small owned wrapper types for values that should satisfy common constraints before they move through an application or library boundary.
The crate has no dependencies and forbids unsafe code.
When To Use It
Use this crate when a value has simple validity rules that should be checked once and then carried as a typed value:
- names and identifiers that must not be empty,
- strings with minimum or maximum character lengths,
- percentages constrained to
0..=100, - ports constrained to
1..=65535, - byte sizes that should display consistently.
When Not To Use It
Do not use this crate as a replacement for domain-specific validation, parsing, serialization, or schema libraries. The types here are intentionally small and general.
Installation
After publishing:
[]
= "0.1"
Until then:
[]
= { = "https://github.com/satyakwok/reliakit", = "reliakit-primitives" }
Examples
Non-empty strings
use NonEmptyStr;
let name = new?;
Bounded strings
use BoundedStr;
type Username = ;
let username = new?;
Numeric primitives
use ;
let limit = from_mb;
let threshold = new?;
let port = new?;
Available Types
NonEmptyStr: owned string that is not empty and not whitespace-only.BoundedStr<MIN, MAX>: owned string constrained by character length.Percent: percentage value from0to100inclusive.Port: TCP/UDP port from1to65535inclusive.ByteSize: byte size value with human-readable display output.
Feature Flags
default = ["std"]std: enablesstd::error::Errorfor primitive errors.alloc: marker feature for allocation-backed usage withoutstd.
no_std
The crate is designed for no_std usage when default features are disabled and alloc is available for string-backed types.
[]
= { = "0.1", = false, = ["alloc"] }
Safety
This crate forbids unsafe code.
Status
Active. The 0.1.x API is considered stable for the current set of types.
License
Licensed under the MIT License. See ../../LICENSE.