sim_citizen/symbol.rs
1//! Parses a namespace/name string into a kernel Symbol.
2
3use sim_kernel::Symbol;
4
5/// Parses `namespace/name` text into a kernel [`Symbol`].
6///
7/// Splits on the first `/` into a qualified symbol; text with no `/` becomes a
8/// bare symbol. The kernel owns `Symbol`; this is the citizen-side spelling of
9/// the symbols recorded in registry rows.
10///
11/// # Examples
12///
13/// ```
14/// # use sim_citizen::parse_symbol;
15/// let qualified = parse_symbol("example/Point");
16/// assert_eq!(qualified.to_string(), "example/Point");
17///
18/// let bare = parse_symbol("Point");
19/// assert_eq!(bare.to_string(), "Point");
20/// ```
21pub fn parse_symbol(text: &str) -> Symbol {
22 match text.split_once('/') {
23 Some((namespace, name)) => Symbol::qualified(namespace.to_owned(), name.to_owned()),
24 None => Symbol::new(text.to_owned()),
25 }
26}