Expand description
Official Rust SDK for the API2Convert file-conversion API.
One call uploads (or references a URL), starts the job, polls it to completion and hands you the result:
use api2convert::{Api2Convert, ConvertOptions};
let client = Api2Convert::new("YOUR_API_KEY")?;
// Convert a local file and save the result into a directory.
let result = client.convert("photo.heic", "jpg")?;
let path = result.save("out/", None)?;
println!("saved {}", path.display());
// Convert a remote URL with target-specific options.
let result = client.convert_with(
"https://example.com/input.png",
"jpg",
ConvertOptions::new().option("quality", 85),
)?;
let bytes = result.contents(None)?;This crate is one of the official API2Convert SDKs (PHP, Python, Java,
Node.js, Go, Ruby, Rust) that implement the same language-agnostic contract
(docs/SDK_CONTRACT.md) and version together.
§Errors
Every fallible call returns Result, whose error is Api2ConvertError.
Match it to react to specific conditions:
match client.convert("in.png", "not-a-format") {
Ok(result) => { let _ = result; }
Err(Api2ConvertError::Validation(e)) => eprintln!("bad request: {}", e.message),
Err(Api2ConvertError::RateLimit { retry_after, .. }) => {
eprintln!("rate limited; retry after {:?}s", retry_after)
}
Err(e) => eprintln!("failed: {e}"),
}§Security
Account key, per-job upload token and download password ride in custom
X-Api2convert-* headers. Secret-bearing requests never follow redirects (only the
self-contained, no-secret download path does), uploads use the per-job token
(never the account key), and no secret ever appears in an error message. See
SECURITY.md.
Re-exports§
pub use cloud::CloudInput;pub use cloud::OutputTarget;
Modules§
- cloud
- Cloud storage connectors: the
CloudInputbuilder and theOutputTargetmodel, plus theprovidervocabulary. - enums
- String-valued enumerations from the API. Unknown values are preserved as-is (never rejected), so a newly-added status or input type does not break the SDK — forward compatibility is a contract requirement.
Structs§
- Api2
Convert - The API2Convert client. Cheap to clone (shares one transport).
- ApiError
Data - Metadata shared by every HTTP error (status ≥ 400).
- Async
Options - Controls for an asynchronous
convert_async. - Client
Builder - Builds an
Api2Convertclient. Obtain one viaApi2Convert::builder. - Contracts
Resource - The account’s contract / plan details (
GET /contracts). Returns free-form JSON. - Conversion
- One conversion within a job.
- Conversion
Result - The outcome of a completed
convert: the finishedJobplus convenience download methods for the selected output. - Conversions
Resource - The conversions catalog (
GET /conversions) — which targets exist and which options each accepts. - Convert
Options - Controls for a synchronous
convert. - File
Download - A handle to a single downloadable output. A download password given at
conversion time (or to
Api2Convert::download) is remembered here and sent automatically; an explicit password argument tosave/contentsoverrides it for that call. - Headers
- A case-insensitive collection of response headers.
- Http
Request - A library-agnostic HTTP request.
- Http
Response - A library-agnostic HTTP response. The body is streamed, never buffered by the sender.
- Input
File - An input file of a job.
- Job
- A conversion job — the central resource. Create it, (upload | add a remote input), start it, poll it to a terminal status, then download its outputs.
- JobMessage
- An entry of a job’s
errors[]/warnings[]. - Jobs
Resource - Full control over the job lifecycle. Most callers only need
Api2Convert::convert, which is built on these. - Output
File - An output file of a job.
uriis a self-contained download URL (no auth, finite TTL); protect it with a download password if the job set one. - Preset
- A saved conversion preset.
- Presets
Resource - Manage saved conversion presets (reusable named target + options).
- Stats
Resource - Usage statistics (
GET /stats/{period}/{value}/{filter}). Returns free-form JSON. - Status
- A job’s status: a
code(seecrate::enums::job_status) and optional human-readableinfo. - Webhook
Event - A verified/parsed webhook delivery: the
Jobit describes plus the full decoded payload. - Webhook
Verifier - Verifies and parses webhook deliveries.
Enums§
- Api2
Convert Error - Every error the SDK can produce.
- Input
- Something to convert: a local file path, a remote URL (
http(s)://…), an in-memory buffer, or a streaming reader.
Constants§
- API_
KEY_ ENV - The environment variable consulted when no API key is passed explicitly.
- DEFAULT_
BASE_ URL - The default API base URL.
- VERSION
- The SDK version. Versioned together with the sibling API2Convert SDKs against
the shared
docs/SDK_CONTRACT.md.
Traits§
- Http
Sender - Sends an
HttpRequestand returns anHttpResponse. A genuine transport failure is returned asApi2ConvertError::Network; a non-2xx status is not an error at this layer (the transport maps it). - Rng
- A
[0, 1)random source for backoff jitter. Tests inject a fixed value for deterministic backoff. - Sleeper
- The delay function used by retry and poll backoff. The default sleeps the current thread; tests inject a no-op recorder.
Type Aliases§
- Result
- Shorthand for a
Resultwhose error isApi2ConvertError.