Struct Atom

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

Source

pub fn value(&self) -> T

Returns a copy of the value stored in the atom.

Examples found in repository?
examples/using_atoms.rs (line 8)
5fn main() {
6    let mut k = KBox::new_atom(42u8);
7    println!("{}", k);
8    assert_eq!(k.value(), 42);
9
10    k.set_value(43);
11
12    assert_eq!(k.value(), 43);
13}
More examples
Hide additional examples
examples/connecting_to_kdb.rs (line 6)
3fn main() -> Result<(), ConnectionError> {
4    let conn = Connection::connect("127.0.0.1", 4200, "", None)?;
5    let result = cast!(conn.eval("2+2").unwrap(); Atom<i64>);
6    println!("{}", result.value());
7
8    //Returning a list of symbols
9    let result = cast!(conn.eval("`a`b`c").unwrap(); List<Symbol>);
10    println!("{:?}", &result[0..]);
11
12    Ok(())
13}
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}
Source

pub fn set_value(&mut self, val: T)

Changes the value stored in th atom.

Examples found in repository?
examples/using_atoms.rs (line 10)
5fn main() {
6    let mut k = KBox::new_atom(42u8);
7    println!("{}", k);
8    assert_eq!(k.value(), 42);
9
10    k.set_value(43);
11
12    assert_eq!(k.value(), 43);
13}

Trait Implementations§

Source§

impl<T: KValue> AsRef<Any> for Atom<T>

Source§

fn as_ref(&self) -> &Any

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: KValue + Debug> Debug for Atom<T>

Source§

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

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

impl<T: KValue + Display> Display for Atom<T>

Source§

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

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

impl From<Atom<Date>> for Date

Source§

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

Converts to this type from the input type.
Source§

impl From<Atom<DateTime>> for DateTime

Source§

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

Converts to this type from the input type.
Source§

impl From<Atom<Minute>> for Minute

Source§

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

Converts to this type from the input type.
Source§

impl From<Atom<Month>> for Month

Source§

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

Converts to this type from the input type.
Source§

impl From<Atom<Second>> for Second

Source§

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

Converts to this type from the input type.
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<Atom<Time>> for Time

Source§

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

Converts to this type from the input type.
Source§

impl From<Atom<Timespan>> for Timespan

Source§

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

Converts to this type from the input type.
Source§

impl From<Atom<Timestamp>> for Timestamp

Source§

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

Converts to this type from the input type.
Source§

impl From<Atom<Uuid>> for Uuid

Source§

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

Converts to this type from the input type.
Source§

impl From<Atom<bool>> for bool

Source§

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

Converts to this type from the input type.
Source§

impl From<Atom<f32>> for f32

Source§

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

Converts to this type from the input type.
Source§

impl From<Atom<f64>> for f64

Source§

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

Converts to this type from the input type.
Source§

impl From<Atom<i16>> for i16

Source§

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

Converts to this type from the input type.
Source§

impl From<Atom<i32>> for i32

Source§

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

Converts to this type from the input type.
Source§

impl From<Atom<i64>> for i64

Source§

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

Converts to this type from the input type.
Source§

impl From<Atom<i8>> for i8

Source§

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

Converts to this type from the input type.
Source§

impl From<Atom<u8>> for u8

Source§

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

Converts to this type from the input type.

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> 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> 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> 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.