fun_with_symbols/
fun_with_symbols.rs

1use kdb::{symbol, KBox, Symbol};
2
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}