pub struct Symbol {
pub namespace: Option<Arc<str>>,
pub name: Arc<str>,
}Expand description
An optionally namespaced name for a runtime entity.
The kernel defines the symbol contract; it is the name that appears in
Expr forms, refs, and registry keys. Names are
reference-counted (Arc<str>), not interned: cloning is cheap, but there is
no global dedup table, so two symbols with equal text are distinct
allocations that merely compare equal.
§Name grammar
A symbol is a namespace (optional) plus a bare name. Bare names are
treated as opaque text by the kernel; the qualified rendering is
namespace/name (or just name when unqualified). as_qualified_str is
therefore not injective when a component contains /:
Symbol::new("a/b") and Symbol::qualified("a", "b") render identically yet
are unequal. Construct symbols at untrusted boundaries with
Symbol::checked, which rejects /, NUL, and control characters so the
qualified rendering stays unambiguous.
§Examples
let plain = Symbol::new("car");
assert_eq!(plain.as_qualified_str(), "car");
let qualified = Symbol::qualified("core", "Bool");
assert_eq!(qualified.as_qualified_str(), "core/Bool");Fields§
§namespace: Option<Arc<str>>The optional namespace component (the part before /).
name: Arc<str>The bare name component.
Implementations§
Source§impl Symbol
impl Symbol
Sourcepub fn checked(name: impl Into<Arc<str>>) -> Result<Self, SymbolError>
pub fn checked(name: impl Into<Arc<str>>) -> Result<Self, SymbolError>
Creates an unqualified symbol after validating the name.
Unlike Symbol::new, this rejects names that would make the qualified
rendering ambiguous or unprintable: names containing / (the
namespace separator), NUL, or any other control character. Codecs and
other untrusted boundaries should adopt this constructor; trusted kernel
call sites may keep using the infallible Symbol::new.
Sourcepub fn qualified(
namespace: impl Into<Arc<str>>,
name: impl Into<Arc<str>>,
) -> Self
pub fn qualified( namespace: impl Into<Arc<str>>, name: impl Into<Arc<str>>, ) -> Self
Creates a symbol qualified by namespace.
Sourcepub fn as_qualified_str(&self) -> String
pub fn as_qualified_str(&self) -> String
Renders the symbol as namespace/name, or just name when unqualified.