l>

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.

l-labs/rust_ipc

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 typeK variantRust type
boolean, byteBool, Byte and vectorsbool, u8
short, int, longShort, Int, Long and vectorsi16, i32, i64
real, floatReal, Float and vectorsf32, f64
char, stringChar, CharVecu8, bytes
symbolSymbol and vectorString
timestamp through timetemporal variantsi64, i32
mixed listList(Vec<K>)nested K values
dict, tableDict(keys, vals), Tablestructured 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.