Symbol

Struct Symbol 

Source
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

Source

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}
Source

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.

Source

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.

Source

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§

Source§

impl Clone for Symbol

Source§

fn clone(&self) -> Symbol

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Symbol

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Symbol

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Display for symbol will always render a string representation of the symbol. If the string contains invalid characters it will strip them from the string. This function will allocate only if the string conatins invalid utf-8 characters.

Source§

impl From<Atom<Symbol>> for Symbol

Source§

fn from(val: Atom<Symbol>) -> Symbol

Converts to this type from the input type.
Source§

impl From<Symbol> for *const i8

Source§

fn from(sym: Symbol) -> Self

Converts to this type from the input type.
Source§

impl Hash for Symbol

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Symbol

Source§

fn eq(&self, other: &Symbol) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Symbol

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.