symbol

Function symbol 

Source
pub fn symbol(s: &str) -> Symbol
Expand description

Helper for succinctly creating a symbol. If the string passed in is not a valid symbol, i.e. it contains embedded nuls, then this function will panic.

Examples found in repository?
examples/using_dictionaries.rs (line 8)
4fn main() {
5    //Symbols use a lot of try_into. Sad.
6    let mut dict = KBox::new_dict();
7
8    dict.insert(symbol("One"), 1i32);
9    dict.insert(symbol("Two"), 2i32);
10    dict.insert(symbol("Three"), 3i32);
11
12    println!("{:?}", cast!(&dict[symbol("Two")]; Atom<Symbol>));
13}
More examples
Hide additional examples
examples/publishing.rs (line 7)
4fn main() {
5    let conn = Connection::connect("127.0.0.1", 4200, "", None).unwrap();
6    let l = list![i32; 1, 2, 3];
7    if let Err(err) = conn.publish("upd", symbol("some_topic"), l) {
8        println!("Publishing failed: {}", err);
9    }
10    println!("Publish succeeded! Probably.");
11}
examples/fun_with_symbols.rs (line 5)
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}