documentation
Rust SDK
Connect to an l server from Rust with the l-rs IPC client.
The Rust SDK is a pure Rust client for the l database IPC protocol. It has no external dependencies, uses no unsafe, and inflates compressed responses transparently.
Install
Add l-rs from GitHub:
[dependencies]
l-rs = { git = "https://github.com/l-labs/rust_ipc" }
Start an l server before connecting:
l -p 5001
First query
use l_rs::{Connection, K};
fn main() -> Result<(), l_rs::LError> {
let mut conn = Connection::connect("localhost", 5001)?;
let r = conn.query("2+2")?;
println!("{r}");
let v: Vec<i32> = conn.query("til 10")?.try_into()?;
assert_eq!(v.len(), 10);
let s = conn.query_with_args("{x+y}", vec![K::Long(2), K::Long(3)])?;
assert_eq!(s, K::Long(5));
Ok(())
}
Use connect_with_auth(host, port, "user:pass") when the server expects credentials. Use send_async(&k) to send a message without reading a reply.
Types
Every result is a K. Atoms are scalar values; vectors are homogeneous Vec<T> values.
| l type | K variant | Rust type |
|---|---|---|
| boolean, byte | Bool, Byte and vectors | bool, u8 |
| short, int, long | Short, Int, Long and vectors | i16, i32, i64 |
| real, float | Real, Float and vectors | f32, f64 |
| char, string | Char, CharVec | u8, bytes |
| symbol | Symbol and vector | String |
| timestamp through time | temporal variants | i64, i32 |
| mixed list | List(Vec<K>) | nested K values |
| dict, table | Dict(keys, vals), Table | structured K values |
From builds a K from a Rust value. TryFrom extracts typed values. Null int and long values use MIN; null floats use NaN. Err(LError::L(msg)) is a server error; other variants are transport failures. Connection is not Send, so use one connection per thread.