pub trait History {
// Required methods
fn current(&self) -> HistoryEntry;
fn push(&mut self, url: &str) -> EntryKey;
fn replace(&mut self, url: &str);
fn back(&mut self);
fn forward(&mut self);
fn can_go_back(&self) -> bool;
fn can_go_forward(&self) -> bool;
fn poll(&mut self, ctx: &Context) -> Option<HistoryEntry>;
// Provided methods
fn shows_links(&self) -> bool { ... }
fn hover_link(&mut self, _url: Option<&str>) { ... }
}Expand description
A session history the router keeps in sync with the current page.
Required Methods§
Sourcefn current(&self) -> HistoryEntry
fn current(&self) -> HistoryEntry
The current entry. Used to pick the initial route.
Sourcefn back(&mut self)
fn back(&mut self)
Moves one entry back. The resulting entry is reported through History::poll.
Sourcefn forward(&mut self)
fn forward(&mut self)
Moves one entry forward. The resulting entry is reported through History::poll.
fn can_go_back(&self) -> bool
fn can_go_forward(&self) -> bool
Sourcefn poll(&mut self, ctx: &Context) -> Option<HistoryEntry>
fn poll(&mut self, ctx: &Context) -> Option<HistoryEntry>
Returns the entry the history moved to by itself since the last call (back/forward,
or the browser’s buttons). Entries the history doesn’t know (e.g. the user edited the
url’s #hash) must be given a fresh key.
ctx can be stored to request a repaint when such a change happens outside a frame.
Provided Methods§
Sourcefn shows_links(&self) -> bool
fn shows_links(&self) -> bool
Whether History::hover_link shows hovered links to the platform, which then also
opens them in a new tab on Ctrl/Cmd/Shift-click (so the router doesn’t follow those).
Sourcefn hover_link(&mut self, _url: Option<&str>)
fn hover_link(&mut self, _url: Option<&str>)
Called after every frame with the url of the link under the pointer, if any.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<H: History + ?Sized> History for Box<H>
A history chosen at runtime, e.g. a MemoryHistory in tests and the default one otherwise.
impl<H: History + ?Sized> History for Box<H>
A history chosen at runtime, e.g. a MemoryHistory in tests and the default one otherwise.
use egui_kit::{History, MemoryHistory, Router, default_history};
let history: Box<dyn History> = if cfg!(test) {
Box::new(MemoryHistory::new("/settings"))
} else {
Box::new(default_history())
};
let app = Router::<()>::new().with_state_and_history((), history);