Use Into<Option<>> trick for to_keyword and to_symbol.

This commit is contained in:
Richard Newman 2017-02-01 17:46:07 -08:00
parent 592dec7241
commit a9929249eb

View file

@ -198,15 +198,15 @@ fn to_ord(value: &Value) -> i32 {
pub struct Pair(Value, Value);
pub fn to_symbol(namespace: Option<&str>, name: &str) -> Value {
if let Some(ns) = namespace {
pub fn to_symbol<'a, T: Into<Option<&'a str>>>(namespace: T, name: &str) -> Value {
if let Some(ns) = namespace.into() {
return Value::NamespacedSymbol(symbols::NamespacedSymbol::new(ns, name));
}
return Value::PlainSymbol(symbols::PlainSymbol::new(name));
}
pub fn to_keyword(namespace: Option<&str>, name: &str) -> Value {
if let Some(ns) = namespace {
pub fn to_keyword<'a, T: Into<Option<&'a str>>>(namespace: T, name: &str) -> Value {
if let Some(ns) = namespace.into() {
return Value::NamespacedKeyword(symbols::NamespacedKeyword::new(ns, name));
}
return Value::Keyword(symbols::Keyword::new(name));