pub struct ResRef { /* private fields */ }Expand description
Canonicalized resource reference.
KotOR resource references are case-insensitive identifiers up to
16 bytes long, stored as Windows-1252-encoded bytes (the engine’s
native encoding). This type holds the bytes in an inline fixed-size
buffer, making it Copy and zero-allocation.
§Validation rules
Accepts any input that round-trips through Windows-1252 encoding.
ASCII bytes pass straight through; non-ASCII chars that have a
Windows-1252 representation (é, ü, £, etc.) get transcoded
to their single-byte Windows-1252 form. Characters with no
Windows-1252 mapping (Chinese, emoji, etc.) are rejected.
The engine itself performs no character validation at all (verbatim
memcpy into a 16-byte buffer). Validation here exists to ensure we
only construct resrefs that can actually be stored in the
engine-native encoding. For the full engine audit, see the
ResRef Validation section of
docs/src/formats/resource_system.md.
§Storage and access
Use Self::as_bytes for byte-level work (writing to disk,
hashing, lint inspection, byte-level comparison). For a string
view, use the Display impl (e.g. format!("{resref}") or
resref.to_string()); it decodes Windows-1252 → UTF-8 on demand.
Implementations§
Source§impl ResRef
impl ResRef
Sourcepub fn new(value: impl AsRef<str>) -> Result<Self, ResRefError>
pub fn new(value: impl AsRef<str>) -> Result<Self, ResRefError>
Creates and validates a new resource reference.
The input is transcoded from UTF-8 to Windows-1252 (the engine’s
native encoding); ASCII letters are lowercased for the
engine’s case-insensitive lookup. Returns
ResRefError::InvalidChar when a character has no
Windows-1252 mapping (Chinese, emoji, etc.) and
ResRefError::TooLong when the encoded form exceeds 16 bytes.
An empty string produces a blank ResRef.
Sourcepub const fn const_new(value: &str) -> Result<Self, ResRefError>
pub const fn const_new(value: &str) -> Result<Self, ResRefError>
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Returns the canonical Windows-1252 bytes that make up this resref.
This is the engine-actual storage form. Use this for byte-level work (writing to disk, hashing, lint inspection of byte patterns, comparing against a byte-string literal).