Expand description
Freedesktop thumbnail cache primitives.
The library exposes typed helpers for resolving the personal thumbnail cache, constructing canonical original identities, validating existing thumbnails, and atomically installing caller-rendered thumbnail PNGs.
use xdg_thumbnail::{
PersonalCacheRoot, PersonalThumbnailLookup, ReadablePersonalOriginalIdentity, ThumbnailSize,
};
fn main() -> xdg_thumbnail::Result<()> {
let root = PersonalCacheRoot::resolve_from_env()?;
let original = ReadablePersonalOriginalIdentity::from_local_path("/home/alice/Pictures/photo.png")?;
match root.lookup_thumbnail_png_bytes(&original, ThumbnailSize::Normal)? {
PersonalThumbnailLookup::Valid(entry) => {
let _png_bytes = entry.png_bytes();
}
PersonalThumbnailLookup::Missing | PersonalThumbnailLookup::Invalid(_) => {}
}
Ok(())
}Owned request types make it straightforward to wrap blocking filesystem work in an async runtime without adding a runtime dependency to this crate. Request constructors perform no filesystem I/O, but local original identity construction does, so build local identities inside the same blocking adapter.
use xdg_thumbnail::{
PersonalCacheRoot, PersonalThumbnailInstallRequest, ReadablePersonalOriginalIdentity, ThumbnailSize,
};
fn spawn_blocking<F, R>(operation: F) -> R
where
F: FnOnce() -> R + Send + 'static,
R: Send + 'static,
{
operation()
}
fn render_thumbnail_png() -> Vec<u8> {
unimplemented!("return PNG bytes produced by the caller's renderer")
}
fn main() -> xdg_thumbnail::Result<()> {
let root = PersonalCacheRoot::resolve_from_env()?;
let rendered_png = render_thumbnail_png();
let installed = spawn_blocking(move || {
let original =
ReadablePersonalOriginalIdentity::from_local_path("/home/alice/Pictures/photo.png")?;
let request = PersonalThumbnailInstallRequest::new(
root,
original,
ThumbnailSize::Normal,
rendered_png,
);
request.install_png_bytes()
})?;
let _path = installed.path();
Ok(())
}Structs§
- Cache
Entry Handle - A handle for a discovered cache entry.
- Cache
Entry Inspection - Policy-neutral inspection facts for a cache entry.
- Cache
Entry Inspection Parts - Owned parts of
CacheEntryInspection. - Display
Thumbnail Rgba8 Lookup Entry - Decoded display RGBA8 pixels from an exact or larger validated cache PNG.
- Display
Thumbnail Rgba8 Lookup Entry Parts - Owned parts of
DisplayThumbnailRgba8LookupEntry. - Failure
Entry Inspection Request - Owned failure-entry inspection request for async or runtime-specific adapters.
- Failure
Entry Inspection Request Parts - Owned parts of
FailureEntryInspectionRequest. - Failure
Entry Write Request - Owned failure-entry write request for async or runtime-specific adapters.
- Failure
Entry Write Request Parts - Owned parts of
FailureEntryWriteRequest. - Failure
Namespace - A validated direct directory name for failure entries.
- Installed
Thumbnail Path - Path result of a successful personal-cache install or failure-entry write.
- Installed
Thumbnail PngBytes - PNG bytes result of a successful personal-cache install or failure-entry write.
- Installed
Thumbnail PngBytes Parts - Owned parts of
InstalledThumbnailPngBytes. - Materialized
Thumbnail Path - Path result of explicit fallback materialization into the personal cache.
- Materialized
Thumbnail Path Parts - Owned parts of
MaterializedThumbnailPath. - Materialized
Thumbnail PngBytes - PNG bytes result of explicit fallback materialization into the personal cache.
- Materialized
Thumbnail PngBytes Parts - Owned parts of
MaterializedThumbnailPngBytes. - Owned
RawThumbnail Image - Owned raw rendered thumbnail pixels.
- Owned
RawThumbnail Image Parts - Owned parts of
OwnedRawThumbnailImage. - Parsed
Thumbnail Png - Decoded facts from a thumbnail PNG.
- Parsed
Thumbnail PngParts - Owned parts of
ParsedThumbnailPng. - Personal
Cache Root - Root directory of the personal thumbnail cache, usually
$XDG_CACHE_HOME/thumbnails. - Personal
Original Identity - Canonical personal URI plus original freshness and write facts needed for validation and writes.
- Personal
Original Uri - A canonical absolute URI identity for entries in the personal thumbnail cache.
- Personal
Thumbnail Inspection Request - Owned personal-cache inspection request for async or runtime-specific adapters.
- Personal
Thumbnail Inspection Request Parts - Owned parts of
PersonalThumbnailInspectionRequest. - Personal
Thumbnail Install Request - Owned personal-cache install request for async or runtime-specific adapters.
- Personal
Thumbnail Install Request Parts - Owned parts of
PersonalThumbnailInstallRequest. - Personal
Thumbnail Lookup Request - Owned personal-cache lookup request for async or runtime-specific adapters.
- Personal
Thumbnail Lookup Request Parts - Owned parts of
PersonalThumbnailLookupRequest. - Personal
Thumbnail Materialization Request - Owned personal-cache fallback materialization request for async or runtime-specific adapters.
- Personal
Thumbnail Materialization Request Parts - Owned parts of
PersonalThumbnailMaterializationRequest. - Personal
Thumbnail RawInstall Request - Owned personal-cache raw install request for async or runtime-specific adapters.
- Personal
Thumbnail RawInstall Request Parts - Owned parts of
PersonalThumbnailRawInstallRequest. - RawThumbnail
Image - Borrowed raw rendered thumbnail pixels.
- Readable
Personal Original Identity - An original identity whose source has been confirmed readable by the caller.
- Shared
Cache Entry Inspection - Read-only inspection facts for an existing shared thumbnail repository entry.
- Shared
Cache Entry Inspection Parts - Owned parts of
SharedCacheEntryInspection. - Shared
Original Facts - Shared-repository lookup facts, including the metadata acceptance policy.
- Shared
Original Metadata - Policy-neutral original freshness facts for shared-repository validation and inspection.
- Shared
Relative Original Uri - A canonical
./-prefixed URI identity for direct children in shared repositories. - Shared
Repository Context - Explicit context for read-only shared repository lookup.
- Shared
Thumbnail Inspection Request - Owned shared-repository inspection request for async or runtime-specific adapters.
- Shared
Thumbnail Inspection Request Parts - Owned parts of
SharedThumbnailInspectionRequest. - Shared
Thumbnail Lookup Request - Owned shared-repository lookup request for async or runtime-specific adapters.
- Shared
Thumbnail Lookup Request Parts - Owned parts of
SharedThumbnailLookupRequest. - Shared
ToPersonal Thumbnail Materialization Request - Owned shared-to-personal fallback materialization request for async adapters.
- Shared
ToPersonal Thumbnail Materialization Request Parts - Owned parts of
SharedToPersonalThumbnailMaterializationRequest. - Thumbnail
Metadata - Freedesktop thumbnail PNG text metadata.
- Thumbnail
Metadata Problem - Key-specific thumbnail metadata problem.
- Thumbnail
Path Lookup Entry - A validated cache path and metadata facts.
- Thumbnail
Path Lookup Entry Parts - Owned parts of
ThumbnailPathLookupEntry. - Thumbnail
PngBytes Lookup Entry - Exact validated PNG bytes and metadata facts.
- Thumbnail
PngBytes Lookup Entry Parts - Owned parts of
ThumbnailPngBytesLookupEntry. - Thumbnail
Rgba8 Lookup Entry - Decoded tightly packed RGBA8 pixels and metadata facts from a validated cache PNG.
- Thumbnail
Rgba8 Lookup Entry Parts - Owned parts of
ThumbnailRgba8LookupEntry. - Thumbnail
Timestamps - Timestamp facts captured for a thumbnail cache entry.
- Unix
Mtime Seconds - Whole Unix epoch seconds used by
Thumb::MTime.
Enums§
- Access
Time Preservation - Whether access time was preserved while inspecting an entry.
- Cache
Directory Problem - Privacy or type problem found in an existing personal-cache directory.
- Cache
Entry Inspection Outcome - Validation confidence and validity for policy-neutral cache inspection.
- Cache
Entry Problem - Policy-neutral problem found while validating or inspecting a cache entry.
- Cache
Namespace - A successful-thumbnail size namespace or a program failure namespace.
- Cache
Path Problem - Problem found in an explicitly supplied cache entry path.
- Cache
Root Problem - Problem found in an explicitly supplied cache root path.
- Nonstandard
Entry Policy - Policy for nonstandard filenames discovered during personal-cache inspection.
- Original
UriIdentity - Original URI identity parsed from a cache entry.
- Personal
Thumbnail Lookup - Result of a validated personal thumbnail cache lookup.
- Personal
Validation Outcome - Validation confidence and validity for a personal-cache entry.
- RawThumbnail
Pixel Format - Explicit raw pixel format accepted by raw thumbnail install APIs.
- Shared
Cache Entry Outcome - Validation state for a shared cache entry inspection.
- Shared
Thumbnail Lookup - Result of a validated shared thumbnail repository lookup.
- Shared
Thumbnail Metadata Policy - Metadata acceptance policy for shared-repository thumbnail lookups.
- Shared
Validation Outcome - Validation confidence and validity for a shared-repository entry.
- Thumbnail
Error - Errors returned by thumbnail cache identity and filesystem operations.
- Thumbnail
Metadata Key - Standard thumbnail metadata key involved in a validation or inspection problem.
- Thumbnail
Metadata Problem Kind - Kind of problem found for a standard thumbnail metadata key.
- Thumbnail
PngBit Depth - PNG sample bit depth reported by
ParsedThumbnailPng. - Thumbnail
PngColor Type - PNG color type reported by
ParsedThumbnailPng. - Thumbnail
Size - A standard Freedesktop thumbnail size directory.
Functions§
- validate_
personal_ failure_ entry - Validates a personal-cache failure entry PNG against a readable original identity.
- validate_
personal_ thumbnail - Validates a personal-cache successful thumbnail PNG against a readable original identity.
- validate_
shared_ thumbnail - Validates a shared-repository successful thumbnail PNG against explicit shared context and policy-neutral original metadata facts.
Type Aliases§
- Result
- Result type used by this crate.