Skip to main content

MediaType

Enum MediaType 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source

pub const fn as_name(self) -> &'static str

Returns the canonical media type name used by the API and CLI.

Source

pub const fn as_mime(self) -> &'static str

Returns the canonical MIME type string.

Source

pub const fn is_lossy(self) -> bool

Reports whether the media type is typically encoded with lossy quality controls.

Source

pub const fn supports_optimization(self) -> bool

Returns true if the format participates in the optimization pipeline.

Source

pub const fn supports_lossy_optimization(self) -> bool

Returns true if the format supports lossy optimization controls.

Source

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.

Source

pub const fn is_raster(self) -> bool

Returns true if this is a raster (bitmap) format, false for vector formats.

Source

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.

Source

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§

Source§

impl Clone for MediaType

Source§

fn clone(&self) -> MediaType

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for MediaType

Source§

impl Debug for MediaType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for MediaType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for MediaType

Source§

impl FromStr for MediaType

Source§

type Err = String

The associated error which can be returned from parsing.
Source§

fn from_str(value: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for MediaType

Source§

fn eq(&self, other: &MediaType) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MediaType

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> To for T
where T: ?Sized,

Source§

fn to<T>(self) -> T
where Self: Into<T>,

Converts to T by calling Into<T>::into.
Source§

fn try_to<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Tries to convert to T by calling TryInto<T>::try_into.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.