Struct mentat::query::Keyword
[−]
[src]
pub struct Keyword(_);
A keyword is a symbol, optionally with a namespace, that prints with a leading colon. This concept is imported from Clojure, as it features in EDN and the query syntax that we use.
Clojure's constraints are looser than ours, allowing empty namespaces or names:
user=> (keyword "" "")
:/
user=> (keyword "foo" "")
:foo/
user=> (keyword "" "bar")
:/bar
We think that's nonsense, so we only allow keywords like :bar
and :foo/bar
,
with both namespace and main parts containing no whitespace and no colon or slash:
let bar = Keyword::plain("bar"); // :bar let foo_bar = Keyword::namespaced("foo", "bar"); // :foo/bar assert_eq!("bar", bar.name()); assert_eq!(None, bar.namespace()); assert_eq!("bar", foo_bar.name()); assert_eq!(Some("foo"), foo_bar.namespace());
If you're not sure whether your input is well-formed, you should use a
parser or a reader function first to validate. TODO: implement read
.
Callers are expected to follow these rules: http://www.clojure.org/reference/reader#_symbols
Future: fast equality (interning?) for keywords.
Methods
impl Keyword
[src]
impl Keyword
impl Keyword
[src]
impl Keyword
pub fn namespaced<N, T>(namespace: N, name: T) -> Keyword where
N: AsRef<str>,
T: AsRef<str>,
[src]
pub fn namespaced<N, T>(namespace: N, name: T) -> Keyword where
N: AsRef<str>,
T: AsRef<str>,
Creates a new Keyword
.
Examples
let keyword = Keyword::namespaced("foo", "bar"); assert_eq!(keyword.to_string(), ":foo/bar");
See also the kw!
macro in the main mentat
crate.
pub fn name(&self) -> &str
[src]
pub fn name(&self) -> &str
pub fn namespace(&self) -> Option<&str>
[src]
pub fn namespace(&self) -> Option<&str>
pub fn components(&'a self) -> (&'a str, &'a str)
[src]
pub fn components(&'a self) -> (&'a str, &'a str)
pub fn is_backward(&self) -> bool
[src]
pub fn is_backward(&self) -> bool
Whether this Keyword
should be interpreted in reverse order. For example,
the two following snippets are identical:
[?y :person/friend ?x]
[?x :person/hired ?y]
[?y :person/friend ?x]
[?y :person/_hired ?x]
Examples
assert!(!Keyword::namespaced("foo", "bar").is_backward()); assert!(Keyword::namespaced("foo", "_bar").is_backward());
pub fn is_forward(&self) -> bool
[src]
pub fn is_forward(&self) -> bool
Whether this Keyword
should be interpreted in forward order.
See symbols::Keyword::is_backward
.
Examples
assert!(Keyword::namespaced("foo", "bar").is_forward()); assert!(!Keyword::namespaced("foo", "_bar").is_forward());
pub fn is_namespaced(&self) -> bool
[src]
pub fn is_namespaced(&self) -> bool
pub fn to_reversed(&self) -> Keyword
[src]
pub fn to_reversed(&self) -> Keyword
Returns a Keyword
with the same namespace and a
'backward' name. See symbols::Keyword::is_backward
.
Returns a forward name if passed a reversed keyword; i.e., this function is its own inverse.
Examples
let nsk = Keyword::namespaced("foo", "bar"); assert!(!nsk.is_backward()); assert_eq!(":foo/bar", nsk.to_string()); let reversed = nsk.to_reversed(); assert!(reversed.is_backward()); assert_eq!(":foo/_bar", reversed.to_string());
pub fn unreversed(&self) -> Option<Keyword>
[src]
pub fn unreversed(&self) -> Option<Keyword>
If this Keyword
is 'backward' (see symbols::Keyword::is_backward
),
return Some('forward name')
; otherwise, return None
.
Examples
let nsk = Keyword::namespaced("foo", "bar"); assert_eq!(None, nsk.unreversed()); let reversed = nsk.to_reversed(); assert_eq!(Some(nsk), reversed.unreversed());
Trait Implementations
impl PartialOrd<Keyword> for Keyword
[src]
impl PartialOrd<Keyword> for Keyword
fn partial_cmp(&self, __arg_0: &Keyword) -> Option<Ordering>
[src]
fn partial_cmp(&self, __arg_0: &Keyword) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &Keyword) -> bool
[src]
fn lt(&self, __arg_0: &Keyword) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &Keyword) -> bool
[src]
fn le(&self, __arg_0: &Keyword) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &Keyword) -> bool
[src]
fn gt(&self, __arg_0: &Keyword) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &Keyword) -> bool
[src]
fn ge(&self, __arg_0: &Keyword) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Clone for Keyword
[src]
impl Clone for Keyword
fn clone(&self) -> Keyword
[src]
fn clone(&self) -> Keyword
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl From<Keyword> for PatternValuePlace
[src]
impl From<Keyword> for PatternValuePlace
fn from(value: Keyword) -> PatternValuePlace
[src]
fn from(value: Keyword) -> PatternValuePlace
Performs the conversion.
impl From<Keyword> for PatternNonValuePlace
[src]
impl From<Keyword> for PatternNonValuePlace
fn from(value: Keyword) -> PatternNonValuePlace
[src]
fn from(value: Keyword) -> PatternNonValuePlace
Performs the conversion.
impl Ord for Keyword
[src]
impl Ord for Keyword
fn cmp(&self, __arg_0: &Keyword) -> Ordering
[src]
fn cmp(&self, __arg_0: &Keyword) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl<'de> Deserialize<'de> for Keyword
[src]
impl<'de> Deserialize<'de> for Keyword
fn deserialize<__D>(
__deserializer: __D
) -> Result<Keyword, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
[src]
fn deserialize<__D>(
__deserializer: __D
) -> Result<Keyword, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Hash for Keyword
[src]
impl Hash for Keyword
fn hash<__H>(&self, __arg_0: &mut __H) where
__H: Hasher,
[src]
fn hash<__H>(&self, __arg_0: &mut __H) where
__H: Hasher,
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Eq for Keyword
[src]
impl Eq for Keyword
impl PartialEq<Keyword> for Keyword
[src]
impl PartialEq<Keyword> for Keyword
fn eq(&self, __arg_0: &Keyword) -> bool
[src]
fn eq(&self, __arg_0: &Keyword) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Keyword) -> bool
[src]
fn ne(&self, __arg_0: &Keyword) -> bool
This method tests for !=
.
impl Display for Keyword
[src]
impl Display for Keyword
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
Print the keyword in EDN format.
Examples
assert_eq!(":baz", Keyword::plain("baz").to_string()); assert_eq!(":bar/baz", Keyword::namespaced("bar", "baz").to_string()); assert_eq!(":bar/_baz", Keyword::namespaced("bar", "baz").to_reversed().to_string()); assert_eq!(":bar/baz", Keyword::namespaced("bar", "baz").to_reversed().to_reversed().to_string());
impl Debug for Keyword
[src]
impl Debug for Keyword
fn fmt(&self, __arg_0: &mut Formatter) -> Result<(), Error>
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter. Read more
impl Serialize for Keyword
[src]
impl Serialize for Keyword
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
[src]
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl From<Keyword> for TypedValue
[src]
impl From<Keyword> for TypedValue
fn from(value: Keyword) -> TypedValue
[src]
fn from(value: Keyword) -> TypedValue
Performs the conversion.