Skip to main content

Embed

Struct Embed 

Source
pub struct Embed<T = Given> { /* private fields */ }
Expand description

A page from another site in a locked frame, such as a video player or a map.

let video = Embed::url("https://www.youtube-nocookie.com/embed/abc")
    .title(Text::from("Product tour"))
    .allow([EmbedPermission::Fullscreen, EmbedPermission::PictureInPicture])
    .aspect(16, 9)
    .click_to_load("/static/tour.jpg");

The frame gets sandbox="allow-scripts allow-same-origin allow-presentation", referrerpolicy="no-referrer" and loading="lazy". When the address is not https or its host is not in the app’s frame-src (App::csp(|c| c.frame_src([...]))), no frame is rendered at all; a warning says why. With Embed::click_to_load the other site is not contacted until the user presses the poster button.

A title is required, because screen readers announce frames by it:

ⓘ
let stack = Stack::new().add(Embed::url("https://player.example.com/v/1"));

Implementations§

Source§

impl Embed<NoTitle>

Source

pub fn url(url: impl Into<String>) -> Self

The address to frame: an https URL or pasted embed code, of which only src is used.

Source

pub fn title(self, title: impl Into<Text>) -> Embed<Given>

What the framed page is, for screen readers. Required.

Source§

impl<T> Embed<T>

Source

pub fn allow( self, permissions: impl IntoIterator<Item = EmbedPermission>, ) -> Self

Browser features the framed page may use. None unless set.

Source

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

Width to height ratio of the frame. 16:9 unless set; zeros are ignored.

Source

pub fn click_to_load(self, poster: impl Into<String>) -> Self

Shows a button first and loads the frame only when it is pressed, so the other site learns nothing about visitors who do not use it. poster is an image shown on the button: a path on the app or an https address on a host of img-src; pass "" for none.

Source

pub fn notice(self, notice: impl Into<Text>) -> Self

A text of the app shown on the click to load button, such as a content warning. It is part of the button’s accessible name, so screen readers read it before the button is pressed. Without Embed::click_to_load it turns the button on with no poster.

let tour = Embed::url("https://video.example.com/embed/tour")
    .title(Text::from("Product tour"))
    .click_to_load("")
    .notice(Text::from("This video is served by another site."));
Source

pub fn remember(self, key: ClientPref<Consent>) -> Self

Remembers that the user pressed the click to load button, under a consent key declared with crate::ClientPref::consent and registered with App::client_prefs, so embeds bound to the same key load at once on later pages and in other tabs for the key’s lifetime. Use it for a notice that should be confirmed once in a while, not on every page that shows such an embed.

pub const EXTERNAL_VIDEO: ClientPref<Consent> =
    ClientPref::consent("external-video", Duration::from_secs(24 * 60 * 60), Purpose::Necessary);

let tour = Embed::url("https://video.example.com/embed/tour")
    .title(Text::from("Product tour"))
    .notice(Text::from("This video is served by another site."))
    .remember(EXTERNAL_VIDEO);

The browser keeps the record in zeyn.state (see crate::ClientPref); no cookie is set and the server never sees it, so cached public pages stay the same for everyone. A remembered frame loads without moving focus (WCAG 2.2 3.2.1 On Focus and 2.4.3 Focus Order); focus moves to the frame only after a real press. The button stays when the record has ended or does not pass its checks, when the app did not register the key, and without JavaScript. Without Embed::click_to_load it turns the button on with no poster.

Trait Implementations§

Source§

impl Complete for Embed<Given>

Source§

impl Component for Embed<Given>

Source§

fn render(&self, out: &mut String, r: &Render<'_>)

Source§

fn schema(&self) -> Json

Schema used by MCP tools and test generation. Include a "type" key.
Source§

fn grid(&self) -> Option<&dyn GridSource>

Source§

fn form(&self) -> Option<&dyn FormSource>

Source§

fn reveal(&self, _field: &str) -> Option<Revealed>

The raw value of a masked field this component shows, for an audited reveal. The server checks the unmask permission before sending it.
Source§

fn import(&self) -> Option<&dyn ImportSource>

CSV import, for components that import rows (see crate::Import).
Source§

fn children(&self) -> &[Node]

Nodes held by a container. Child i of the node at path p has the path p.i.
Source§

fn eager_children(&self) -> &[Node]

Children rendered with the page. Others, such as closed lazy tabs, load when first shown.
Source§

fn source(&self, _key: &str) -> Option<&dyn DataSource>

Data the component fetches through an action, by key (a field name for lookups).
Source§

fn shortcuts(&self) -> Vec<&str>

Keyboard shortcuts of the component’s own links, as declared, for the clash checks of App::check and App::check_page.
Source§

impl<T> From<Embed<T>> for Node
where Embed<T>: Complete + 'static,

Source§

fn from(e: Embed<T>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> Freeze for Embed<T>
where PhantomData<T>: Freeze,

§

impl<T> RefUnwindSafe for Embed<T>

§

impl<T> Send for Embed<T>
where PhantomData<T>: Send,

§

impl<T> Sync for Embed<T>
where PhantomData<T>: Sync,

§

impl<T> Unpin for Embed<T>
where PhantomData<T>: Unpin,

§

impl<T> UnsafeUnpin for Embed<T>

§

impl<T> UnwindSafe for Embed<T>

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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