pub struct Atom<T> { /* private fields */ }
Expand description
Atoms are the base primitive values in rust-kdb. You can create a new atom by calling
KBox::new_atom
, or using the From
/Into
traits on a value.
§Examples
use kdb::{KBox, Atom};
let a = KBox::new_atom(42u8); // Creates a KBox<Atom<u8>>
let b: KBox<Atom<u8>> = 27u8.into();
println!("{} dudes!", a.value() + b.value());
Implementations§
Source§impl<T: KValue> Atom<T>
impl<T: KValue> Atom<T>
Sourcepub fn value(&self) -> T
pub fn value(&self) -> T
Returns a copy of the value stored in the atom.
Examples found in repository?
More examples
examples/fun_with_symbols.rs (line 15)
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}
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Atom<T>
impl<T> RefUnwindSafe for Atom<T>where
T: RefUnwindSafe,
impl<T> !Send for Atom<T>
impl<T> !Sync for Atom<T>
impl<T> Unpin for Atom<T>where
T: Unpin,
impl<T> UnwindSafe for Atom<T>where
T: UnwindSafe,
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