Guides
Quickstart

Quickstart

The shortest path from cargo new to "I have a workspace with one file in it." The full runnable example lives at examples/embedded.rs (opens in a new tab) in the fslite source tree.

1. Add the dependencies

Cargo.toml
[dependencies]
fslite-core = "0.1"
fslite-sqlite = "0.1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

2. Open an in-memory database

src/main.rs
use fslite_core::{RequestContext, VirtualPath, WriteSource};
use fslite_sqlite::SqliteFileSystem;
 
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let fs = SqliteFileSystem::open_in_memory(Default::default()).await?;
    Ok(())
}

open_in_memory is great for tests; for a real workload use SqliteFileSystem::open(path, options) with a file path. The database holds as many workspaces as you like — each one is fully isolated.

3. Create a workspace and a context

let workspace = fs.create_workspace(Default::default()).await?;
let ctx = RequestContext::trusted(workspace.id);

RequestContext::trusted skips capability checks for the same identity the workspace belongs to. For an HTTP server, build the context from an AuthProvider's AuthenticatedActor instead — that's the topic of the AuthProvider guide.

4. Write, read, list

let path = VirtualPath::parse("/hello.txt")?;
fs.write(
    &ctx,
    &path,
    WriteSource::from_bytes(b"hello".to_vec()),
    Default::default(),
).await?;
 
assert!(fs.exists(&ctx, &path, Default::default()).await?);
 
let usage = fs.workspace_usage(&ctx).await?;
println!("workspace usage: {usage:?}");

Writes are streamed and chunked; the call returns once the data is committed and a fresh Node (with its new Revision) is in hand.

5. Run

cargo run

Expected output ends with the workspace-usage printout.

Next steps