Skip to main content

ImageAsset

Struct ImageAsset 

Source
pub struct ImageAsset {
    pub id: String,
    pub path: String,
    pub hash: DocumentId,
    pub format: ImageFormat,
    pub size: u64,
    pub width: Option<u32>,
    pub height: Option<u32>,
    pub alt: Option<String>,
    pub title: Option<String>,
    pub attribution: Option<String>,
    pub variants: Vec<ImageVariant>,
}
Expand description

An image asset embedded in a Codex document.

Fields§

§id: String

Unique identifier for the image.

§path: String

Path within the archive (e.g., “assets/images/logo.png”).

§hash: DocumentId

Content hash for verification.

§format: ImageFormat

Image format.

§size: u64

File size in bytes.

§width: Option<u32>

Image width in pixels (for raster images).

§height: Option<u32>

Image height in pixels (for raster images).

§alt: Option<String>

Alternative text for accessibility.

§title: Option<String>

Optional title/caption.

§attribution: Option<String>

Source attribution or copyright.

§variants: Vec<ImageVariant>

Resolution variants for responsive images.

Each variant represents the same image at a different resolution, typically for different screen densities (1x, 2x, 3x).

Implementations§

Source§

impl ImageAsset

Source

pub fn new(id: impl Into<String>, format: ImageFormat) -> Self

Create a new image asset.

Source

pub fn with_hash(self, hash: DocumentId) -> Self

Set the content hash.

Source

pub const fn with_size(self, size: u64) -> Self

Set the file size.

Source

pub fn with_dimensions(self, width: u32, height: u32) -> Self

Set the dimensions.

Source

pub fn with_alt(self, alt: impl Into<String>) -> Self

Set the alternative text.

Source

pub fn with_title(self, title: impl Into<String>) -> Self

Set the title.

Source

pub fn with_attribution(self, attribution: impl Into<String>) -> Self

Set the attribution.

Source

pub fn with_path(self, path: impl Into<String>) -> Self

Set a custom path.

Source

pub fn with_variant(self, variant: ImageVariant) -> Self

Add a resolution variant.

Source

pub fn with_variants(self, variants: Vec<ImageVariant>) -> Self

Add multiple resolution variants.

Source

pub fn has_variants(&self) -> bool

Check if this image has resolution variants.

Source

pub fn variant_for_scale(&self, scale: f32) -> Option<&ImageVariant>

Get the variant for a specific scale, if available.

Source

pub fn best_variant_for_width(&self, target_width: u32) -> Option<&ImageVariant>

Get the best variant for a given target width.

Returns the smallest variant that is at least as wide as the target, or the largest available variant if none are wide enough.

Trait Implementations§

Source§

impl Asset for ImageAsset

Source§

fn id(&self) -> &str

Get the asset’s unique identifier.
Source§

fn path(&self) -> &str

Get the path to the asset file within the archive.
Source§

fn hash(&self) -> &DocumentId

Get the content hash of the asset.
Source§

fn size(&self) -> u64

Get the size in bytes.
Source§

fn mime_type(&self) -> &str

Get the MIME type.
Source§

impl Clone for ImageAsset

Source§

fn clone(&self) -> ImageAsset

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ImageAsset

Source§

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

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

impl<'de> Deserialize<'de> for ImageAsset

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for ImageAsset

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ImageAsset

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ImageAsset

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,