Skip to main content

Image

Struct Image 

Source
pub struct Image<'a> {
    pub alt: &'a str,
    pub caption: Option<&'a str>,
    pub fit: Fit,
}
Expand description

A picture, and what it says to someone who is not looking at it.

§No source

Act’s split, for Act’s reason. A source is an address, and this crate has no notion of an address: it says what a thing is and the caller keeps what it points at. The three findings dropped from 0.11.0 were all this same shape.

It matters more here than it does for a control, because a picture is the one member where the address is most of what a webview needs and none of what the description knows. quasi_router::Node::Image carries the URL, the way it carries an Action for a control.

§Why alt is not optional

Every other host has to draw something, and for two of the three the alt text is not a fallback but the whole rendering: a terminal without a graphics protocol has the words and nothing else. Making it optional would make “this picture is invisible on a terminal” the default, and the description would be carrying a webview assumption in its shape.

An image that genuinely says nothing — a rule, a spacer, a decoration repeating what the text beside it already said — is an empty alt, which is the same thing HTML means by it and is a claim rather than an oversight.

Fields§

§alt: &'a str

What the picture says, for anything not showing it.

Empty means the picture is decorative and adds nothing to the text around it. See the type’s own docs on why this is not an Option.

§caption: Option<&'a str>

A visible line under the picture, where the app wants one.

Distinct from alt and the difference is who it is for: a caption is content everybody reads, alt text is what stands in for the picture. A screenshot captioned “The library view” still needs alt text describing what is in the shot.

§fit: Fit

How it sits in the box it is given.

Implementations§

Source§

impl<'a> Image<'a>

Source

pub const fn new(alt: &'a str) -> Self

A picture that carries its own proportions.

Source

pub const fn caption(self, caption: &'a str) -> Self

A visible line under it.

Source

pub const fn fit(self, fit: Fit) -> Self

How it sits in its box.

Source

pub const fn speaks(self) -> bool

Whether the picture adds anything for someone not looking at it.

A renderer with no way to show a picture uses this to decide between drawing the alt text and drawing nothing at all. Both are correct and the difference is this flag: standing in for a decorative rule with the word “decoration” is worse than leaving the space empty.

Trait Implementations§

Source§

impl<'a> Clone for Image<'a>

Source§

fn clone(&self) -> Image<'a>

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<'a> Copy for Image<'a>

Source§

impl<'a> Debug for Image<'a>

Source§

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

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

impl<'a> Eq for Image<'a>

Source§

impl<'a> Hash for Image<'a>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> PartialEq for Image<'a>

Source§

fn eq(&self, other: &Image<'a>) -> bool

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

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

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for Image<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Image<'a>

§

impl<'a> RefUnwindSafe for Image<'a>

§

impl<'a> Send for Image<'a>

§

impl<'a> Sync for Image<'a>

§

impl<'a> Unpin for Image<'a>

§

impl<'a> UnsafeUnpin for Image<'a>

§

impl<'a> UnwindSafe for Image<'a>

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, 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> 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.