{
  "kind": "documentation",
  "format": 1,
  "note": "Reference text, not instructions. One verified relate sample from https://relatedb.ai/docs/get-started/rust/: the program exactly as the page shows it, the standard output a run of it recorded (npm run docs:samples compares every replay with it byte for byte), the relate client build, toolchain and platform of the last replay, and how the docs' sample runner builds and runs it. Before launch every client is a source build, not a published package; verified.client names the upstream commit it was built from, and verified.docs_engine the build the rest of the docs were recorded from.",
  "id": "program",
  "url": "https://relatedb.ai/docs/get-started/rust/samples/program.json",
  "page": {
    "id": "get-started/rust",
    "title": "Embed relate in a Rust program",
    "url": "https://relatedb.ai/docs/get-started/rust/",
    "md_url": "https://relatedb.ai/docs/get-started/rust.md"
  },
  "section": {
    "anchor": "put-it-together",
    "heading": "Put it together",
    "url": "https://relatedb.ai/docs/get-started/rust/#put-it-together"
  },
  "language": "rust",
  "client": "Rust",
  "file": "main.rs",
  "env": null,
  "code": "use std::collections::BTreeMap;\nuse std::process;\n\nuse relate::{error_info, Connection, Database, Value};\n\nconst TEAM: &str = \"\nCREATE (ada:Person {name: 'Ada', role: 'engineer'}),\n       (grace:Person {name: 'Grace', role: 'engineer'}),\n       (noor:Person {name: 'Noor', role: 'maintainer'}),\n       (relate:Project {name: 'relate', language: 'Rust'}),\n       (tck:Project {name: 'opencypher-tck', language: 'Gherkin'}),\n       (ada)-[:WORKS_ON {since: 2024}]->(relate),\n       (grace)-[:WORKS_ON {since: 2023}]->(relate),\n       (grace)-[:WORKS_ON {since: 2022}]->(tck),\n       (noor)-[:MAINTAINS]->(relate),\n       (ada)-[:KNOWS]->(grace)\n\";\n\nconst TEAM_OF: &str = \"\nMATCH (p:Person)-[w:WORKS_ON]->(:Project {name: $project})\nRETURN p.name AS name, w.since AS since\nORDER BY since\n\";\n\nfn ensure_team(conn: &mut Connection) -> relate::Result<()> {\n    let result = conn.query(\"MATCH (p:Person) RETURN count(p) AS n\")?;\n    let people = result.rows[0][0].as_int().unwrap_or(0);\n    if people == 0 {\n        conn.query(TEAM)?;\n        println!(\"created the team graph\");\n    } else {\n        println!(\"found {people} people\");\n    }\n    Ok(())\n}\n\nfn report(conn: &mut Connection, project: &str) -> relate::Result<()> {\n    println!(\"{project}\");\n    let params = BTreeMap::from([(\"project\".to_string(), Value::String(project.into()))]);\n    for row in conn.query_with_params(TEAM_OF, params)?.rows {\n        let name = row[0].as_string().unwrap_or(\"\");\n        let since = row[1].as_int().unwrap_or(0);\n        println!(\"  {name} since {since}\");\n    }\n    Ok(())\n}\n\nfn run() -> relate::Result<()> {\n    let db = Database::open(\"./team.rl\")?;\n    let mut conn = db.connect()?;\n    ensure_team(&mut conn)?;\n    report(&mut conn, \"relate\")?;\n    report(&mut conn, \"opencypher-tck\")?;\n    Ok(())\n}\n\nfn main() {\n    if let Err(e) = run() {\n        eprintln!(\"relate error {}: {e}\", error_info(&e).gql_status);\n        process::exit(1);\n    }\n}",
  "code_sha256": "c04093b5bd4b47c538d1868b536f6c090d8634cf1580f1781015ddfddbe15aa1",
  "source_sha256": "464325b0b4685aa40ec88de70d7f0bf76e669ec159db287b56798b8767bdec07",
  "output": {
    "text": "created the team graph\nrelate\n  Grace since 2023\n  Ada since 2024\nopencypher-tck\n  Grace since 2022",
    "sha256": "1c4d6ad9d85b2e1c50b54653bde7361157564ad399ffab2ebfa5cfc05724e414"
  },
  "verified": {
    "version": "0.1.2",
    "client": {
      "label": "Rust",
      "package": "relate",
      "engine_commit": "f0c09d2",
      "client_commit": "f0c09d2",
      "build": "The relate crate from a checkout of upstream v0.1.2 (f0c09d2), as a path dependency of a template project carrying that commit's Cargo.lock and rust-toolchain.toml.",
      "toolchain": {
        "rust": "1.88.0"
      }
    },
    "packages": [],
    "replayed": "2026-11-09",
    "platform": "macOS on arm64",
    "docs_engine": {
      "version": "0.1.2",
      "commit": "f0c09d2",
      "source_build": false
    }
  },
  "run": {
    "runner": "npm run docs:samples",
    "setup": "bash scripts/samples/setup.sh --upstream <path to the relate checkout>",
    "variables": [
      "RELATE_CARGO",
      "RELATE_RUST_PROJECT"
    ],
    "program": "<build dir>/main.rs",
    "files": [
      {
        "path": "<build dir>/Cargo.toml",
        "from": "$RELATE_RUST_PROJECT/Cargo.toml",
        "note": "its [[bin]] path set to \"main.rs\""
      },
      {
        "path": "<build dir>/Cargo.lock",
        "from": "$RELATE_RUST_PROJECT/Cargo.lock"
      },
      {
        "path": "<build dir>/rust-toolchain.toml",
        "from": "$RELATE_RUST_PROJECT/rust-toolchain.toml"
      },
      {
        "path": "<build dir>/relate-sample",
        "from": "$RELATE_RUST_PROJECT/target/release/relate-sample",
        "note": "the built binary, copied out after the build"
      }
    ],
    "build": {
      "command": [
        "$RELATE_CARGO",
        "build",
        "--release",
        "--locked",
        "--offline",
        "--quiet"
      ],
      "environment": {
        "DO_NOT_TRACK": "1",
        "CARGO_TARGET_DIR": "$RELATE_RUST_PROJECT/target",
        "CARGO_TERM_COLOR": "never"
      },
      "directory": "<build dir>",
      "timeout_s": 600
    },
    "run": {
      "command": [
        "<build dir>/relate-sample"
      ],
      "environment": {
        "DO_NOT_TRACK": "1"
      },
      "directory": "<run dir>",
      "timeout_s": 60
    },
    "passes": "It exits 0 within 60 s and prints at least one line on standard output.",
    "output": "Standard output, with line endings as \\n, trailing spaces and blank lines removed, and the temporary directories' paths written as `.`; standard error is not recorded.",
    "placeholders": {
      "<run dir>": "a fresh, empty temporary directory: the program's working directory, deleted afterwards",
      "<build dir>": "a second fresh temporary directory, where a compiled sample is built",
      "$NAME": "a variable from the env.sh that scripts/samples/setup.sh writes (described in its header)"
    }
  }
}
