Struct egg::Symbol [−][src]
pub struct Symbol(_);
Expand description
An interned string.
Internally, egg
frequently compares Var
s and elements of
Language
s. To keep comparisons fast, egg
provides Symbol
a simple
wrapper providing interned strings.
You may wish to use Symbol
in your own Language
s to increase
performance and keep enode sizes down (a Symbol
is only 4 bytes,
compared to 24 for a String
.)
A Symbol
is simply a wrapper around an integer.
When creating a Symbol
from a string, egg
looks up it up in a global
table, returning the index (inserting it if not found).
That integer is used to cheaply implement
Copy
, Clone
, PartialEq
, Eq
, PartialOrd
, Ord
, and Hash
.
The internal symbol cache leaks the strings, which should be fine if you only put in things like variable names and identifiers.
Example
use egg::Symbol;
assert_eq!(Symbol::from("foo"), Symbol::from("foo"));
assert_eq!(Symbol::from("foo"), "foo".parse().unwrap());
assert_ne!(Symbol::from("foo"), Symbol::from("bar"));
Implementations
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for Symbol
impl UnwindSafe for Symbol
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.