[][src]Struct slack_blocks::blocks::image::Contents

pub struct Contents { /* fields omitted */ }

Image Block

slack api docs 🔗

A simple image block, designed to make those cat photos really pop.

Implementations

impl Contents[src]

pub fn from_alt_text_and_url(
    alt_text: impl ToString,
    image_url: impl ToString
) -> Self
[src]

Create an image block, with a url and a brief description for situations where the image cannot be rendered.

Arguments

  • alt_text - A plain-text summary of the image. This should not contain any markup. Maximum length for this field is 2000 characters.

  • image_url - The URL of the image to be displayed. Maximum length for this field is 3000 characters.

Example

use slack_blocks::blocks::{Block, image};

let url = "https://www.cheese.com/favicon.ico";
let image: Block = image::Contents::from_alt_text_and_url("a small image of cheese.", url).into();

// < send to slack api >

pub fn with_title(self, title: impl Into<Plain>) -> Self[src]

Set a plain-text title to be displayed next to your image

Arguments

  • title - An optional title for the image in the form of a Plaintext text object 🔗. Maximum length for the text in this field is 2000 characters.

Example

use slack_blocks::blocks::{Block, image};

let url = "https://www.cheese.com/favicon.ico";
let image: Block = image::Contents::from_alt_text_and_url("a small image of cheese.", url)
    .with_title("here is an image of some cheese:")
    .into();

// < send block to slack's API >

pub fn with_block_id(self, block_id: impl ToString) -> Self[src]

Set the block_id for interactions on an existing image::Contents

Arguments

  • block_id - A string acting as a unique identifier for a block. You can use this block_id when you receive an interaction payload to identify the source of the action 🔗. If not specified, a block_id will be generated. Maximum length for this field is 255 characters.

Example

use slack_blocks::blocks::{Block, image};

let url = "https://www.cheese.com/favicon.ico";
let image: Block = image::Contents::from_alt_text_and_url("a small image of cheese.", url)
    .with_title("here is an image of some cheese:")
    .with_block_id("msg_id_12346")
    .into();

// < send block to slack's API >

pub fn validate(&self) -> Result<(), ValidationErrors>[src]

Validate that this Image block agrees with Slack's model requirements

Errors

  • If with_block_id was called with a block id longer than 255 chars
  • If with_title was called with a title longer than 2000 chars
  • If from_url_and_alt_text was called with alt_text longer than 2000 chars
  • If from_url_and_alt_text was called with image_url longer than 3000 chars

Example

use slack_blocks::blocks;

let long_string = std::iter::repeat(' ').take(256).collect::<String>();

let block = blocks::image
    ::Contents
    ::from_alt_text_and_url("", "")
    .with_block_id(long_string);

assert_eq!(true, matches!(block.validate(), Err(_)));

Trait Implementations

impl Clone for Contents[src]

impl Debug for Contents[src]

impl Default for Contents[src]

impl<'de> Deserialize<'de> for Contents[src]

impl From<Contents> for Block[src]

impl Hash for Contents[src]

impl PartialEq<Contents> for Contents[src]

impl Serialize for Contents[src]

impl StructuralPartialEq for Contents[src]

impl Validate for Contents[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.