Add Into<String> to symbol::* constructors. Fixes #199

This commit is contained in:
Jordan Santell 2017-01-28 22:51:46 -08:00
parent c6fa14c0c8
commit 18279fdd3c

View file

@ -80,11 +80,14 @@ 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<T>(namespace: T, name: T) -> Self where T: Into<String> {
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 }
}
}
@ -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<T>(namespace: T, name: T) -> Self where T: Into<String> {
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 }
}
}