Pre: add Variable::from_valid_name, TypedValue::{typed_string,typed_ns_keyword}.
This commit is contained in:
parent
439f3a2283
commit
460fdac252
2 changed files with 39 additions and 4 deletions
|
@ -93,6 +93,20 @@ impl TypedValue {
|
|||
&TypedValue::Keyword(_) => ValueType::Keyword,
|
||||
}
|
||||
}
|
||||
|
||||
/// Construct a new `TypedValue::Keyword` instance by cloning the provided
|
||||
/// values. This is expensive, so this might
|
||||
/// be best limited to tests.
|
||||
pub fn typed_ns_keyword(ns: &str, name: &str) -> TypedValue {
|
||||
TypedValue::Keyword(NamespacedKeyword::new(ns, name))
|
||||
}
|
||||
|
||||
/// Construct a new `TypedValue::String` instance by cloning the provided
|
||||
/// value. This is expensive, so this might
|
||||
/// be best limited to tests.
|
||||
pub fn typed_string(s: &str) -> TypedValue {
|
||||
TypedValue::String(s.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
// Put this here rather than in `db` simply because it's widely needed.
|
||||
|
@ -141,9 +155,9 @@ impl SQLValueType for ValueType {
|
|||
fn test_typed_value() {
|
||||
assert!(TypedValue::Boolean(false).is_congruent_with(None));
|
||||
assert!(TypedValue::Boolean(false).is_congruent_with(ValueType::Boolean));
|
||||
assert!(!TypedValue::String("foo".to_string()).is_congruent_with(ValueType::Boolean));
|
||||
assert!(TypedValue::String("foo".to_string()).is_congruent_with(ValueType::String));
|
||||
assert!(TypedValue::String("foo".to_string()).is_congruent_with(None));
|
||||
assert!(!TypedValue::typed_string("foo").is_congruent_with(ValueType::Boolean));
|
||||
assert!(TypedValue::typed_string("foo").is_congruent_with(ValueType::String));
|
||||
assert!(TypedValue::typed_string("foo").is_congruent_with(None));
|
||||
}
|
||||
|
||||
/// Bit flags used in `flags0` column in temporary tables created during search,
|
||||
|
|
|
@ -44,6 +44,27 @@ pub type SrcVarName = String; // Do not include the required syntactic
|
|||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct Variable(pub PlainSymbol);
|
||||
|
||||
impl Variable {
|
||||
pub fn as_str(&self) -> &str {
|
||||
(self.0).0.as_str()
|
||||
}
|
||||
|
||||
pub fn to_string(&self) -> String {
|
||||
(self.0).0.clone()
|
||||
}
|
||||
|
||||
pub fn name(&self) -> PlainSymbol {
|
||||
self.0.clone()
|
||||
}
|
||||
|
||||
/// Return a new `Variable`, assuming that the provided string is a valid name.
|
||||
pub fn from_valid_name(name: &str) -> Variable {
|
||||
let s = PlainSymbol::new(name);
|
||||
assert!(s.is_var_symbol());
|
||||
Variable(s)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait FromValue<T> {
|
||||
fn from_value(v: &edn::Value) -> Option<T>;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue