Changelog

Rust SDK

Call every Document API operation from Rust, with generated types, against a SuperDoc process your code starts.

Rust SDK

A backend written in Rust that edits DOCX files needs the same operations the editor uses: accept tracked changes, add comments, query text, save. Without typed bindings, you build each request's JSON by hand and parse each response yourself.

From 2.25.0, the superdoc-sdk crate gives you generated Rust types and methods for the Document API. It drives a native SuperDoc process and binds each open document to its own session.

Install and run

The crate needs Rust 1.85 or newer and Tokio:

cargo add superdoc-sdk
cargo add serde_json@1
cargo add tokio@1 --features macros,rt

Client::connect needs the SuperDoc runtime that matches the crate. The guide's example resolves it from a local cache with RuntimeManifest::resolve and calls RuntimeManifest::install when it isn't there yet. In production, install it during the build so the service starts without downloading anything.

This function from the guide accepts every tracked change in an open document and saves the result to a separate file:

async fn accept_all(document: &Document) -> Result<(), Box<dyn Error>> {
    let decision: DocTrackChangesDecideBoundParams =
        serde_json::from_value(json!({
            "decision": "accept",
            "target": { "kind": "all" }
        }))?;
    document.api().track_changes().decide(&decision).await?;

    document
        .api()
        .save(
            &DocSaveBoundParams::new()
                .with_out("./contract.accepted.docx".into())
                .with_force(true),
        )
        .await?;
    Ok(())
}

Every operation has a Rust method

Every operation in the Document API reference has a method on document.api(), with namespaces and names in snake case:

ReferenceRust
doc.trackChanges.decide(...)document.api().track_changes().decide(...).await
doc.comments.create(...)document.api().comments().create(...).await
doc.query.match(...)document.api().query().match_(...).await

Each method takes a generated parameter type. Build simple ones with the constructor and with_* methods. For nested inputs, copy the JSON from the reference into json! and convert it with serde_json::from_value.

Errors

A rejected operation returns a superdoc_sdk::Error. Match on its code, such as TARGET_NOT_FOUND.

Current guides