Merge pull request #213 from mozilla/199

Add Into<String> to symbol::* constructors. Fixes #199
This commit is contained in:
Jordan Santell 2017-01-30 13:35:12 -08:00 committed by GitHub
commit 359d356dd9

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 }
}
}