pub struct Symbol(/* private fields */);Expand description
Represents a KDB Symbol (interned string) Implements basic symbol operations for efficiency Can be converted to/from strings
Implementations§
Source§impl Symbol
impl Symbol
Sourcepub fn new<T: AsRef<str>>(st: T) -> Result<Symbol, SymbolError>
pub fn new<T: AsRef<str>>(st: T) -> Result<Symbol, SymbolError>
Create a new symbol from the specified string. If the string is too long, or contains an embedded nul character, then it returns an error.
Examples found in repository?
examples/fun_with_symbols.rs (line 8)
3fn main() {
4 //Create two identical symbols in different ways, and check that they are equal.
5 let sym = symbol("Hello, World");
6 // Note: converting a string into a symbol is not an infallible operation
7 // rust strings can contain embedded nuls, whereas symbols cannot.
8 let sym_2 = Symbol::new(String::from("Hello") + ", World").unwrap();
9 assert_eq!(sym, sym_2);
10
11 // As an atom:
12 let atom = KBox::new_atom(sym);
13 let atom_2 = KBox::new_atom(Symbol::new(String::from("Hello") + ", World").unwrap());
14
15 assert_eq!(atom.value(), atom_2.value());
16
17 // Note that because rust strings are utf-8, and symbols have no encoding requirement,
18 // this may not display the same way as you will see it in kdb, especially if the string is
19 // not a valid ASCII or utf-8 string.
20 println!("{}", sym);
21}Sourcepub unsafe fn new_unchecked<T: AsRef<str>>(st: T) -> Symbol
pub unsafe fn new_unchecked<T: AsRef<str>>(st: T) -> Symbol
Creates a new symbol, skipping the safety checks for length
§Safety
Any string passed in must not contain embedded nul characters (\0).
It’s length must be less than or equal to isize::MAX.
Sourcepub fn try_as_str(&self) -> Result<&'static str, ConversionError>
pub fn try_as_str(&self) -> Result<&'static str, ConversionError>
Attempts to convert to a valid utf-8 string. This will return an error if the string contains invalid utf-8 characters. This function does not allocate.
Sourcepub unsafe fn as_str_unchecked(&self) -> &'static str
pub unsafe fn as_str_unchecked(&self) -> &'static str
Converts the symbol to a rust str without checking if it is valid.
§Safety
The string must be valid UTF-8. It’s length must be less than or equal to isize::MAX.
Trait Implementations§
impl Copy for Symbol
impl Eq for Symbol
Auto Trait Implementations§
impl Freeze for Symbol
impl RefUnwindSafe for Symbol
impl !Send for Symbol
impl !Sync for Symbol
impl Unpin for Symbol
impl UnwindSafe for Symbol
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more