Struct History

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

The Web History API.

The History API represents the URL and forward/backward buttons in the browser. It’s modeled as a stack where URLs can be pushed/popped, and a cursor can be moved forward/backward along the stack.

History also implements Stream which returns a url every time the cursor is moved along the stack. The only time this event is not triggered is when the cursor moves because of a new entry being pushed onto the stack.

Implementations§

Source§

impl History

Source

pub fn new() -> Self

Create a new instance of History.

Source

pub fn len(&self) -> usize

Returns the number of urls in the History stack.

Source

pub fn is_empty(&self) -> bool

Returns true if the History stack contains no items.

Source

pub fn current(&self) -> String

Get the current url from the History stack.

Source

pub fn push(&self, url: &str)

Push a new url onto the history stack.

Source

pub fn pop(&self)

Pop a url from the history stack.

Source

pub fn replace(&self, url: &str)

Replace the url currently on the stack with another url.

Source

pub async fn move_by(&self, delta: i32)

Move the cursor forwards and backwards through the History stack depending on the value of the parameter.

Passing a value of 0 will reload the page.

Source

pub async fn move_next(&self)

Moves the cursor to the next url in the History stack.

Source

pub async fn move_prev(&self)

Moves the cursor to the previous url in the History stack.

Source

pub async fn reload(&self)

Reload the current url, like the Refresh button.

Trait Implementations§

Source§

impl Debug for History

Source§

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

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

impl Default for History

Source§

fn default() -> Self

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

impl Stream for History

Source§

fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Self::Item>>

Return URLs generated by moving the cursor on the stack. This is equivalent to listening for the "popstate" event.

Source§

type Item = String

Values yielded by the stream.
Source§

fn size_hint(&self) -> (usize, Option<usize>)

Returns the bounds on the remaining length of the stream. Read more
Source§

impl<'pin> Unpin for History
where PinnedFieldsOf<__History<'pin>>: Unpin,

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