pub struct TwoDaName(/* private fields */);Expand description
A validated 2DA table name (e.g. racialtypes, appearance).
Wraps ResRef so cache keys are distinguishable from arbitrary
resrefs at the type level. Layers an ASCII-only check on top of
ResRef’s broader Windows-1252 acceptance: vanilla K1 2DA names
are pure ASCII, and chitin.key’s filename table is ASCII-only,
so an extended-character 2DA name would not resolve anyway.
The name does not include the .2da extension – the
ResourceTypeCode supplies that at resolver lookup time.
Implementations§
Source§impl TwoDaName
impl TwoDaName
Sourcepub fn new(name: impl AsRef<str>) -> Result<Self, ResRefError>
pub fn new(name: impl AsRef<str>) -> Result<Self, ResRefError>
Creates a 2DA name from a string.
2DA filenames are conventionally ASCII; this constructor
enforces that invariant on top of ResRef’s broader
Windows-1252 acceptance, since extended-character 2DA names
would not round-trip through chitin.key’s ASCII-only
filename table anyway.
Sourcepub fn as_resref(&self) -> &ResRef
pub fn as_resref(&self) -> &ResRef
Returns a reference to the underlying ResRef for resolver
lookups that take &ResRef directly.
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the canonical lowercase string form of the name,
suitable for passing to TwoDaCache::twoda without an
extra round trip through TwoDaName::new.
TwoDaName enforces an ASCII-only invariant on construction
(2DA filenames are conventionally ASCII), so this can return
a borrowed &str directly.
Sourcepub const fn from_static(name: &'static str) -> Self
pub const fn from_static(name: &'static str) -> Self
const-friendly constructor for pub const table-name
declarations.
Validation runs at compile time via ResRef::const_new; an
invalid input panics during compilation rather than at first
use. Mirrors http::HeaderName::from_static. Use this only
for hardcoded vanilla / known table names whose validity you
can verify by inspection – runtime-discovered names should
go through Self::new instead.