Crate newstr
Simple macros for declaring String-base new types.
This crate provides simple macros that generate String based new types. The two primary macros
implement the validity rules for the new type by either 1) providing a predicate that is used by
the is_valid associated function, or 2) providing a function to parse and return a string which
is then called by FromStr::from_str.
Both of these methods produce a new type, with the following:
- An associated predicate function
is_validthat returnstrueif the string provided would be a valid value for the type. - This type derives implementations of
Clone,Debug,PartialEq,PartialOrd,Eq,Ord, andHash. - An implementation of
DisplayforTthat simply returns the inner value. - An implementation of
From<T>forString. - An implementation of
DerefforTwith the target typestr. - An implementation of
FromStr.
Example
The following example constructs a new string type that implements an Identifier value. This
value must be ASCII, alphanumeric, the '_' character and must not be empty.
use ;
use FromStr;
use Deref;
is_valid_newstring!;
assert!;
assert!;
assert!;
assert!;
assert_eq!;
assert_eq!;