Expand description
Shared library entry points for the truss project.
§The public API
What this page lists is the API. Nothing else in the crate is, and the sections below say what that means for a version number.
While the version is 0.x, a minor release may change any of it. From 1.0 on, the
shape here is what semantic versioning covers: adding an export or a field to a
#[non_exhaustive] type is a minor release, removing or renaming an export is a major
one, and the minimum supported Rust version in Cargo.toml is raised only in a minor
release. This page is the Rust crate’s half of the promise. The other surfaces state
their own half beside what they specify: the CLI’s subcommands, flags, and exit codes in
docs/problems.md, the HTTP server’s routes, query vocabulary, and headers in
docs/api-reference.md, and each npm package’s exports and option keys in its own
README. The signed URL format is older than all of them and carries a stronger promise,
in docs/signed-url-spec.md, which holds even before 1.0.
Everything the crate exports is re-exported here, at the root. The module tree is private, so a path through it is not part of the API and does not compile:
use truss::core::TransformOptions;The types that grow as truss grows are #[non_exhaustive], so a field a later version
adds is a minor change rather than a breaking one. A caller starts from default(), or
from a constructor, and assigns:
use truss::TransformOptions;
let options = TransformOptions { width: Some(800), ..TransformOptions::default() };use truss::TransformOptions;
let mut options = TransformOptions::default();
options.width = Some(800);
assert_eq!(options.width, Some(800));The value types are exhaustive on purpose, because none of them can gain a field without becoming a different idea: a rectangle is four numbers, a colour is four channels, a size is two, and a quality target is a metric and a threshold. Their literals and their patterns keep working.
use truss::{CropRegion, Dimensions, Rgba8};
let region = CropRegion { x: 0, y: 0, width: 10, height: 10 };
let colour = Rgba8 { r: 1, g: 2, b: 3, a: 255 };
let size = Dimensions::new(10, 10);
assert_eq!((region.width, colour.a, size.height), (10, 255, 10));Structs§
- Artifact
- A decoded or otherwise classified artifact handled by the Core layer.
- Artifact
Metadata - Metadata that the Core layer can carry between decode and encode steps.
- Crop
Region - An explicit crop region applied before resize.
- Dimensions
- A (width, height) pair that prevents accidental transposition of dimensions.
- RawArtifact
- Raw input bytes before media-type detection has completed.
- Rgba8
- A simple 8-bit RGBA color.
- Rotation
- Clockwise rotation in whole degrees, applied after auto-orientation.
- Server
Config - Signed
Watermark Params - Builds a signed public transform URL for the server adapter.
- Target
Quality - A perceptual quality target used when binary-searching a lossy encode quality.
- Transform
Options - Raw transform options before defaulting and validation has completed.
- Transform
Options Payload - Transform
Request - A complete transform request for the Core layer.
- Transform
Result - The result of a successful transform, containing the output artifact and any warnings.
- Watermark
Input - A watermark image to composite onto the output.
Enums§
- Fit
- Resize behavior for bounded transforms.
- LogLevel
- Log verbosity level for the server.
- Media
Type - Supported media types for the current implementation phase.
- Metadata
Kind - Categories of image metadata that may be present in an artifact.
- Optimize
Mode - Optimization policy applied near the final encoding stage.
- Position
- Positioning behavior for bounded transforms.
- Quality
Metric - Perceptual metric used for lossy optimization quality targeting.
- Signed
UrlSource - Source selector used when generating a signed public transform URL.
- Transform
Error - Errors returned by Core validation or backend execution.
- Transform
Warning - A non-fatal warning emitted during a transform operation.
- Trusted
Proxy - A trusted proxy specification: either a single IP address or a CIDR block.
Constants§
- MAX_
OUTPUT_ PIXELS - Maximum number of pixels in the output image (width × height).
Functions§
- bind_
addr - Returns the bind address for the HTTP server adapter.
- run_cli
- Runs the command-line adapter and returns a process exit code.
- serve_
once_ with_ config - Serves exactly one request with an explicit server configuration.
- serve_
with_ config - Serves requests with an explicit server configuration.
- sign_
public_ url - sign_
public_ url_ with_ method - Like
sign_public_urlbut allows the caller to specify the HTTP method included in the canonical string (e.g."GET"or"HEAD"). - sniff_
artifact - Inspects raw bytes, detects the media type, and extracts best-effort metadata.
- transform
- Dispatches a transform request to the appropriate codec based on the input media type.
Type Aliases§
- LogHandler
- Runtime configuration for the HTTP server adapter.