On this page· 5

Rust quickstart

  • file format 6
  • Rust SDK 1.0 preview

Get the Rust SDK from the Cintilé registry, then run one program that writes a pack with three records, opens it, prints the records, and saves the pack as sample.plxi.

Get the SDK

  1. Sign in at cr.cintile.io (available on request), the Cintilé container registry, and create an access token for Cargo.

    Checking a pack needs only standard tools. See Check a pack.

  2. Tell Cargo where the registry is. Add these lines to config.toml in Cargo’s home folder, $CARGO_HOME:

    config.toml
    [registries.cintile]
    index = "sparse+https://cr.cintile.io/cargo/index/"
    credential-provider = ["cargo:token"]
    
  3. Give Cargo the token. It asks for it once and keeps it:

    Terminal
    cargo login --registry cintile
    
  4. Make a new package with cargo new my-pack. Cargo reads the registry lines from .cargo in your home folder, so the package needs only the SDK in its Cargo.toml, under [dependencies]:

    Terminal
    cargo new my-pack
    
    Cargo.toml
    [dependencies]
    plxi-sdk = { version = "1.0.0-rc2", registry = "cintile" }
    
  5. Put the program below in src/main.rs and run it with cargo run. Cargo fetches the SDK from the registry on the first build.

Needs the Rust SDKRust 1.97.1 · edition 2024 · Linux

src/main.rsrust
// Write a pack in memory, open it, and read the records back.
use plxi_sdk::{write, OpenOptions, Pack, Record};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // A record is one JSON object with a string member "k" (its kind).
    let lines = [
        r#"{"k":"rel","src":"e1","tgt":"e2","kind":"knows"}"#,
        r#"{"k":"ent","id":"e2","t":"Person"}"#,
        r#"{"k":"ent","id":"e1","t":"Person","name":"Ada","salience":0.5}"#,
    ];
    let records = lines
        .iter()
        .map(|l| Record::from_json_line(l))
        .collect::<Result<Vec<_>, _>>()?;

    // `write` returns the whole pack as bytes. No file is touched.
    let bytes = write(&records, None)?;

    // Opening verifies the pack by default (digest, header, record count).
    let pack = Pack::from_bytes(bytes, OpenOptions::default())?;
    assert_eq!(pack.record_count(), 3);
    assert!(!pack.has_appendix());

    // Records come back in the format's sort order (entities before
    // relations), spelled the way the writer emits them.
    let out: Vec<String> = pack
        .records()
        .map(|r| r.map(|rec| rec.json_line().to_string()))
        .collect::<Result<_, _>>()?;
    assert_eq!(
        out,
        [
            concat!(
                r#"{"k":"ent","v":1,"id":"e1","t":"Person","#,
                r#""name":"Ada","salience":0.5,"stub":false}"#
            ),
            r#"{"k":"ent","v":1,"id":"e2","t":"Person","stub":false}"#,
            r#"{"k":"rel","v":1,"src":"e1","tgt":"e2","kind":"knows"}"#,
        ]
    );
    for line in &out {
        println!("{line}");
    }
    println!("sha256 = {}", pack.sha256_hex());

    // Keep a copy on disk, for checking with standard tools.
    std::fs::write("sample.plxi", pack.to_bytes())?;
    println!("wrote sample.plxi, {} bytes", pack.to_bytes().len());
    Ok(())
}
Output
{"k":"ent","v":1,"id":"e1","t":"Person","name":"Ada","salience":0.5,"stub":false}
{"k":"ent","v":1,"id":"e2","t":"Person","stub":false}
{"k":"rel","v":1,"src":"e1","tgt":"e2","kind":"knows"}
sha256 = 068f161e337da4b2b0c319a3539b9c62f4b15715d0f3c4de8e1664e5ef66bb28
wrote sample.plxi, 544 bytes

Ran with cargo run · exit status 0

What came back, and why it differs

  • Order. The relation went in first and came out last. A writer emits records in sort-key order, and entities sort before relations.
  • Spelling. Each line gained "v":1, the record's own format version, and each entity gained "stub":false, a member the writer always emits.
  • The digest. The same records give the same bytes, so the same digest: 068f161e…bb28 on every run.
  • The file. The last line is the size of sample.plxi, the pack written to disk.

How this program ran

  1. 1. The steps above were followed on Linux, in a new package made with cargo new my-pack.
  2. 2. In place of the registry, Cargo built plxi-sdk from a copy of its source on the same machine; its build line began Compiling plxi-sdk v1.0.0-rc2. The dependency line in Cargo.toml stayed as step 4 shows it.
  3. 3. The program was saved as src/main.rs and run with cargo run.

Check the saved file

sample.plxi is the pack used on the no-SDK page. Its digest can be recomputed there with sha256sum. Check a pack with standard tools

Next

Sections