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.
impl MemoryExternalUrlOpener
Provides the operations defined for MemoryExternalUrlOpener.
Sourcepub fn new() -> Self
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());Sourcepub fn opened_urls(&self) -> Vec<String>
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);Sourcepub fn take_opened_urls(&self) -> Vec<String>
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());Sourcepub fn fail_next(&self, error: OpenUrlError)
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
impl Clone for MemoryExternalUrlOpener
Source§fn clone(&self) -> MemoryExternalUrlOpener
fn clone(&self) -> MemoryExternalUrlOpener
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for MemoryExternalUrlOpener
impl Default for MemoryExternalUrlOpener
Source§fn default() -> MemoryExternalUrlOpener
fn default() -> MemoryExternalUrlOpener
Source§impl ExternalUrlOpener for MemoryExternalUrlOpener
Implements the ExternalUrlOpener contract for MemoryExternalUrlOpener.
impl ExternalUrlOpener for MemoryExternalUrlOpener
Implements the ExternalUrlOpener contract for MemoryExternalUrlOpener.
Source§fn open(&self, url: &ExternalUrl) -> Result<(), OpenUrlError>
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§
impl Freeze for MemoryExternalUrlOpener
impl !RefUnwindSafe for MemoryExternalUrlOpener
impl !Send for MemoryExternalUrlOpener
impl !Sync for MemoryExternalUrlOpener
impl Unpin for MemoryExternalUrlOpener
impl !UnwindSafe for MemoryExternalUrlOpener
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<A> IntoClickAction<A> for Awhere
A: Clone + 'static,
impl<A> IntoClickAction<A> for Awhere
A: Clone + 'static,
Source§fn into_click_action(self) -> ClickAction<A>
fn into_click_action(self) -> ClickAction<A>
Implements the into_click_action helper used by this module.