nyar_wasm/symbols/identifiers/
convert.rs1use super::*;
2
3impl From<&str> for Identifier {
4 fn from(value: &str) -> Self {
5 Self::from_str(value).unwrap()
6 }
7}
8
9impl From<Arc<str>> for Identifier {
10 fn from(value: Arc<str>) -> Self {
11 Self::from_str(&value).unwrap()
12 }
13}
14impl FromStr for Identifier {
15 type Err = SyntaxError;
16
17 fn from_str(s: &str) -> Result<Self, Self::Err> {
19 let names: Vec<Arc<str>> = s.split("::").map(Arc::from).collect();
20 match names.as_slice() {
21 [] => Err(SyntaxError::new("empty identifier")),
22 [name] => Ok(Identifier { namespace: vec![], name: name.clone() }),
23 [path @ .., name] => Ok(Identifier { namespace: path.to_vec(), name: name.clone() }),
24 }
25 }
26}