Skip to main content

IdentifierDomain

Struct IdentifierDomain 

Source
pub struct IdentifierDomain;
Expand description

A strict domain for identifiers that must follow strict naming rules

This domain is suitable for cases where keys must be valid identifiers in programming languages or databases:

  • Must start with a letter or underscore
  • Can contain letters, numbers, and underscores only
  • Case-sensitive
  • No consecutive underscores

§Examples

use domain_key::{Key, IdentifierDomain};

type IdKey = Key<IdentifierDomain>;

let key = IdKey::new("valid_identifier")?;
assert_eq!(key.as_str(), "valid_identifier");

Trait Implementations§

Source§

impl Debug for IdentifierDomain

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Domain for IdentifierDomain

Source§

const DOMAIN_NAME: &'static str = "identifier"

Human-readable name for this domain Read more
Source§

impl KeyDomain for IdentifierDomain

Source§

const MAX_LENGTH: usize = 64

Maximum length for keys in this domain Read more
Source§

const EXPECTED_LENGTH: usize = 20

Optimization hint: expected average key length for this domain Read more
Source§

const TYPICALLY_SHORT: bool = true

Optimization hint: whether keys in this domain are typically short (≤32 chars) Read more
Source§

const CASE_INSENSITIVE: bool = false

Whether keys in this domain are case-insensitive Read more
Source§

const HAS_CUSTOM_VALIDATION: bool = true

Whether this domain has custom validation rules Read more
Source§

fn allowed_characters(c: char) -> bool

Check which characters are allowed for this domain Read more
Source§

fn allowed_start_character(c: char) -> bool

Check if a character is allowed at the start of a key Read more
Source§

fn validate_domain_rules(key: &str) -> Result<(), KeyParseError>

Domain-specific validation rules Read more
Source§

fn validation_help() -> Option<&'static str>

Get domain-specific help text for validation errors Read more
Source§

fn examples() -> &'static [&'static str]

Get examples of valid keys for this domain Read more
Source§

const HAS_CUSTOM_NORMALIZATION: bool = false

Whether this domain has custom normalization rules Read more
Source§

const FREQUENTLY_COMPARED: bool = false

Optimization hint: whether keys in this domain are frequently compared Read more
Source§

const FREQUENTLY_SPLIT: bool = false

Optimization hint: whether keys in this domain are frequently split Read more
Source§

fn normalize_domain(key: Cow<'_, str>) -> Cow<'_, str>

Domain-specific normalization Read more
Source§

fn is_reserved_prefix(_key: &str) -> bool

Check if a key has a reserved prefix for this domain Read more
Source§

fn is_reserved_suffix(_key: &str) -> bool

Check if a key has a reserved suffix for this domain Read more
Source§

fn default_separator() -> char

Get the default separator character for this domain Read more
Source§

fn requires_ascii_only(_key: &str) -> bool

Check if the key contains only ASCII characters Read more
Source§

fn min_length() -> usize

Get the minimum allowed length for keys in this domain Read more
Source§

fn allowed_end_character(c: char) -> bool

Check if a character is allowed at the end of a key Read more
Source§

fn allowed_consecutive_characters(prev: char, curr: char) -> bool

Check if two consecutive characters are allowed Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.