Struct MemoryExternalUrlOpener

Source
pub struct MemoryExternalUrlOpener { /* private fields */ }
Expand description

Deterministic opener for headless runtimes and tests.

Clones share recorded URLs and the one-shot error slot through Rc<RefCell<_>>. The type is neither Send nor Sync. Successful opens append exact URL strings without a capacity bound; tests should drain them when appropriate.

§Examples

use ailloli_ui_runtime::app::{ExternalUrl, ExternalUrlOpener, MemoryExternalUrlOpener};
let opener = MemoryExternalUrlOpener::new();
let alias = opener.clone();
alias.open(&ExternalUrl::parse("https://example.com")?)?;
assert_eq!(opener.opened_urls(), ["https://example.com"]);

Implementations§

Source§

impl MemoryExternalUrlOpener

Provides the operations defined for MemoryExternalUrlOpener.

Source

pub fn new() -> Self

Creates an opener with an empty log and no scheduled failure.

§Examples
use ailloli_ui_runtime::app::MemoryExternalUrlOpener;
let opener = MemoryExternalUrlOpener::new();
assert!(opener.opened_urls().is_empty());
Source

pub fn opened_urls(&self) -> Vec<String>

Clones and returns all successful URL sources in call order.

This is O(total stored URL bytes) and does not clear the log.

§Panics

Panics on a conflicting borrow through a reentrant alias.

§Examples
use ailloli_ui_runtime::app::{ExternalUrl, ExternalUrlOpener, MemoryExternalUrlOpener};
let opener = MemoryExternalUrlOpener::new();
opener.open(&ExternalUrl::parse("https://example.com/a")?)?;
assert_eq!(opener.opened_urls(), ["https://example.com/a"]);
assert_eq!(opener.opened_urls().len(), 1);
Source

pub fn take_opened_urls(&self) -> Vec<String>

Drains and returns all successful URL sources in call order.

A second call returns an empty vector until another successful open.

§Panics

Panics on a conflicting borrow through a reentrant alias.

§Examples
use ailloli_ui_runtime::app::{ExternalUrl, ExternalUrlOpener, MemoryExternalUrlOpener};
let opener = MemoryExternalUrlOpener::new();
opener.open(&ExternalUrl::parse("https://example.com")?)?;
assert_eq!(opener.take_opened_urls(), ["https://example.com"]);
assert!(opener.take_opened_urls().is_empty());
Source

pub fn fail_next(&self, error: OpenUrlError)

Makes the next open attempt return error without recording its URL.

Calling this again before an attempt replaces the pending error. Clones observe and consume the same one-shot slot.

§Panics

Panics on a conflicting borrow through a reentrant alias.

§Examples
use ailloli_ui_runtime::app::{ExternalUrl, ExternalUrlOpener, MemoryExternalUrlOpener, OpenUrlError};
let opener = MemoryExternalUrlOpener::new();
let url = ExternalUrl::parse("https://example.com")?;
opener.fail_next(OpenUrlError::Unavailable);
assert_eq!(opener.open(&url), Err(OpenUrlError::Unavailable));
assert_eq!(opener.open(&url), Ok(()));

Trait Implementations§

Source§

impl Clone for MemoryExternalUrlOpener

Source§

fn clone(&self) -> MemoryExternalUrlOpener

Returns a copy 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 Default for MemoryExternalUrlOpener

Source§

fn default() -> MemoryExternalUrlOpener

Returns the “default value” for a type. Read more
Source§

impl ExternalUrlOpener for MemoryExternalUrlOpener

Implements the ExternalUrlOpener contract for MemoryExternalUrlOpener.

Source§

fn open(&self, url: &ExternalUrl) -> Result<(), OpenUrlError>

Attempts to open the validated external URL.

§Errors

Returns and consumes the error installed by Self::fail_next, if any.

§Panics

Panics on a conflicting reentrant borrow of the opener’s local state.

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, 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<A> IntoClickAction<A> for A
where A: Clone + 'static,

Source§

fn into_click_action(self) -> ClickAction<A>

Implements the into_click_action helper used by this module.

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> Props for T
where T: Clone + 'static,