#[non_exhaustive]pub enum MediaType {
Jpeg,
Png,
Webp,
Avif,
Svg,
Bmp,
Tiff,
Gif,
}Expand description
Supported media types for the current implementation phase.
§Examples
use truss::MediaType;
use std::str::FromStr;
let mt = MediaType::from_str("png").unwrap();
assert_eq!(mt, MediaType::Png);
assert_eq!(mt.as_name(), "png");
assert_eq!(mt.as_mime(), "image/png");
assert!(!mt.is_lossy());
assert!(mt.is_raster());
assert!(MediaType::Jpeg.is_lossy());
assert!(!MediaType::Svg.is_raster());Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Jpeg
JPEG image data.
Png
PNG image data.
Webp
WebP image data.
Avif
AVIF image data.
Svg
SVG image data.
Bmp
BMP image data.
Tiff
TIFF image data.
Gif
GIF image data.
GIF is an input-only format: truss decodes it but never encodes it, the same way
it treats a raster input requesting SVG output. Requesting gif output returns
TransformError::UnsupportedOutputMediaType.
Implementations§
Source§impl MediaType
impl MediaType
Sourcepub const fn as_name(self) -> &'static str
pub const fn as_name(self) -> &'static str
Returns the canonical media type name used by the API and CLI.
Sourcepub const fn is_lossy(self) -> bool
pub const fn is_lossy(self) -> bool
Reports whether the media type is typically encoded with lossy quality controls.
Sourcepub const fn supports_optimization(self) -> bool
pub const fn supports_optimization(self) -> bool
Returns true if the format participates in the optimization pipeline.
Sourcepub const fn supports_lossy_optimization(self) -> bool
pub const fn supports_lossy_optimization(self) -> bool
Returns true if the format supports lossy optimization controls.
Sourcepub const fn supports_icc_profile(self) -> bool
pub const fn supports_icc_profile(self) -> bool
Returns true if the encoded format can carry an embedded ICC profile.
AVIF signals color through the container’s colr box rather than a profile truss can
write, and BMP/TIFF/SVG output has no profile path in this pipeline.
Sourcepub const fn is_raster(self) -> bool
pub const fn is_raster(self) -> bool
Returns true if this is a raster (bitmap) format, false for vector formats.
Sourcepub const fn is_encodable(self) -> bool
pub const fn is_encodable(self) -> bool
Returns true if truss can encode this format, not merely decode it.
GIF is decode-only: animation, palette quantization, and frame disposal are a
different problem from the single-frame pipeline, so truss reads GIF input and
writes one of the formats it fully supports. SVG is encodable only in the sense
that an SVG input can be sanitized back out as SVG, which
crate::codecs::transform handles on its own path.
Sourcepub const fn default_output(self) -> Self
pub const fn default_output(self) -> Self
The output format to use when a request does not name one.
Normally that is the input’s own format, so a transform without an explicit
format does not silently re-encode into something else. A decode-only input has
no such option: GIF falls back to PNG, which is lossless and reproduces a palette
and a transparent color index exactly.
Every adapter that has to resolve a missing format goes through here, so the rule cannot drift between the CLI, the server, and the WASM build.
§Examples
use truss::MediaType;
assert_eq!(MediaType::Jpeg.default_output(), MediaType::Jpeg);
assert_eq!(MediaType::Gif.default_output(), MediaType::Png);Trait Implementations§
impl Copy for MediaType
impl Eq for MediaType
impl StructuralPartialEq for MediaType
Auto Trait Implementations§
impl Freeze for MediaType
impl RefUnwindSafe for MediaType
impl Send for MediaType
impl Sync for MediaType
impl Unpin for MediaType
impl UnsafeUnpin for MediaType
impl UnwindSafe for MediaType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more