string_intern/
validator.rs

1use std::fmt;
2use std::error::Error;
3
4use Symbol;
5
6
7/// This is validator trait you should implement for your own symbols
8///
9/// In reality this trait serves three purposes:
10///
11/// 1. Validates that atom contains only value you expect it to contain
12/// 2. Identifies the type i.e. `type S1 = Symbol<V1>` and
13///    `type S2 = Symbol<V2>` are different and incompatible types
14/// 3. Allows to override `Display` trait for your own symbol
15pub trait Validator {
16    type Err: Error;
17    fn validate_symbol(&str) -> Result<(), Self::Err>;
18    fn display(value: &Symbol<Self>, fmt: &mut fmt::Formatter) -> fmt::Result {
19        write!(fmt, "i{:?}", value.as_ref())
20    }
21}