TofuPilot Rust Client
Rust client for the TofuPilot REST API. Async, typed, with retries and request lifecycle hooks.
Installation
Add to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["full"] }
Quick Start
use TofuPilot;
use *;
async
Available Resources
| Resource | Methods | Docs |
|---|---|---|
| Runs | list, create, get, update, delete | docs/sdks/runs |
| Procedures | list, create, get, update, delete | docs/sdks/procedures |
| Units | list, create, get, update, delete, add_child, remove_child | docs/sdks/units |
| Parts | list, create, get, update, delete | docs/sdks/parts |
| Batches | list, create, get, update, delete | docs/sdks/batches |
| Stations | list, create, get, get_current, update, remove | docs/sdks/stations |
| Revisions | create, get, update, delete | docs/sdks/revisions |
| Versions | create, get, delete | docs/sdks/versions |
| Attachments | initialize, finalize, delete, upload_file, upload_bytes, download_file | docs/sdks/attachments |
| User | list | docs/sdks/user |
All model types are documented in docs/models/.
Builder Pattern
Every API call uses the builder pattern. Required fields are enforced at send time:
// Optional fields are chained before .send()
let runs = client.runs.list
.outcomes
.part_numbers
.limit
.sort_by
.sort_order
.send
.await?;
for run in &runs.data
File Upload
The SDK provides high-level helpers that handle the three-step upload flow (initialize → PUT → finalize) in a single call:
// Upload from disk
let upload = client.attachments.upload_file.await?;
// Or upload raw bytes
let csv = b"header\nrow1\nrow2";
let upload = client.attachments.upload_bytes.await?;
// Link to a run
client.runs.update
.id
.attachments
.send
.await?;
// Download a file
client.attachments.download_file.await?;
Phases & Measurements
use *;
let now = now;
let run = client.runs.create
.procedure_id
.serial_number
.part_number
.outcome
.started_at
.ended_at
.phases
.send
.await?;
Error Handling
All API errors are typed:
use Error;
match client.runs.get.id.send.await
Retries
The client automatically retries on 429 (rate limit) and 5xx errors with exponential backoff. Configure via ClientConfig:
use ClientConfig;
use Duration;
let client = with_config;
Hooks
Inspect or modify requests and responses:
use Hooks;
let hooks = new
.on_before_request
.on_after_error;
let client = with_config;
Nullable Fields
Some fields distinguish between "not sent" and "explicitly null". These use NullableField<T>:
use NullableField;
// Has a value (From<T> impl)
let field: = "hello".to_string.into;
// Convenience constructors
let field = value;
let field: = null;
Builder methods handle this automatically — you never need to construct NullableField manually:
client.runs.create
.procedure_version // sets Value("1.2.3")
.procedure_version_null // sets Null
// omitted fields default to Absent
Self-Hosted
Point the client at your own TofuPilot instance:
let client = with_config;
Per-Request Overrides
Override server URL or timeout for individual requests:
let result = client.runs.list
.server_url
.timeout
.send
.await?;