diff --git a/edn/src/symbols.rs b/edn/src/symbols.rs index 23e5e8f9..dd99440c 100644 --- a/edn/src/symbols.rs +++ b/edn/src/symbols.rs @@ -80,16 +80,19 @@ impl PlainSymbol { } impl NamespacedSymbol { - pub fn new(namespace: &str, name: &str) -> Self { - assert!(!name.is_empty(), "Symbols cannot be unnamed."); - assert!(!namespace.is_empty(), "Symbols cannot have an empty non-null namespace."); + pub fn new(namespace: T, name: T) -> Self where T: Into { + let n = name.into(); + let ns = namespace.into(); - NamespacedSymbol { name: name.to_string(), namespace: namespace.to_string() } + assert!(!n.is_empty(), "Symbols cannot be unnamed."); + assert!(!ns.is_empty(), "Symbols cannot have an empty non-null namespace."); + + NamespacedSymbol { name: n, namespace: ns } } } impl Keyword { - pub fn new(name: T) -> Self where T: Into{ + pub fn new(name: T) -> Self where T: Into { let n = name.into(); assert!(!n.is_empty(), "Keywords cannot be unnamed."); @@ -98,12 +101,14 @@ impl Keyword { } impl NamespacedKeyword { - pub fn new(namespace: &str, name: &str) -> Self { - assert!(!name.is_empty(), "Keywords cannot be unnamed."); - assert!(!namespace.is_empty(), "Keywords cannot have an empty non-null namespace."); + pub fn new(namespace: T, name: T) -> Self where T: Into { + let n = name.into(); + let ns = namespace.into(); + assert!(!n.is_empty(), "Keywords cannot be unnamed."); + assert!(!ns.is_empty(), "Keywords cannot have an empty non-null namespace."); // TODO: debug asserts to ensure that neither field matches [ :/]. - NamespacedKeyword { name: name.to_string(), namespace: namespace.to_string() } + NamespacedKeyword { name: n, namespace: ns } } }