Skip to main content

Name

Trait Name 

Source
pub trait Name: Sized + AsRef<str> {
    const KIND: &'static str;
    const MAX_LEN: usize = 64;

    // Provided methods
    fn validate_char(offset: usize, ch: char) -> Result<(), NameError> { ... }
    fn validate(s: &str) -> Result<(), NameError> { ... }
}
Expand description

The validation contract shared by every name kind in the system.

Implementers pick the permitted character class and length cap by overriding Self::validate_char and Self::MAX_LEN. The default Self::validate implementation enforces the shared “non-empty, legal identifier start, every character passes validate_char” rule.

Required Associated Constants§

Source

const KIND: &'static str

Human-readable kind label, used in error messages and Debug.

Provided Associated Constants§

Source

const MAX_LEN: usize = 64

Maximum byte length (UTF-8). Default 64 — override when a larger ceiling is natural (plan names, for example).

Provided Methods§

Source

fn validate_char(offset: usize, ch: char) -> Result<(), NameError>

Called once per character to decide membership.

The default admits ASCII identifier characters plus - and ., which is a reasonable class for almost every name kind we ship.

Source

fn validate(s: &str) -> Result<(), NameError>

Validate the given string as a name of this kind.

Called from each newtype’s constructor. Implementations that need stricter or looser rules override Self::validate_char and / or this method wholesale.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Name for FacetKey

Source§

const KIND: &'static str = "FacetKey"

Source§

impl Name for FacetValue

Source§

const KIND: &'static str = "FacetValue"

Source§

impl Name for LabelKey

Source§

const KIND: &'static str = "LabelKey"

Source§

impl Name for PortName

Source§

const KIND: &'static str = "PortName"

Source§

impl Name for TagKey

Source§

const KIND: &'static str = "TagKey"

Source§

impl Name for ExportName

Source§

const KIND: &'static str = "ExportName"

Source§

impl Name for TypeId

Source§

const KIND: &'static str = "TypeId"

Source§

impl Name for ElementName

Source§

const KIND: &'static str = "ElementName"

Source§

impl Name for ParameterName

Source§

const KIND: &'static str = "ParameterName"