pub struct RouterState { /* private fields */ }Expand description
Core navigation state that tracks history, registered routes, and match cache.
This struct owns the navigation history stack and provides methods for
pushing, replacing, and traversing entries. Route matching results are
cached in a HashMap to avoid repeated tree walks within a single path.
§Examples
use gpui_navigator::RouterState;
let mut state = RouterState::new();
assert_eq!(state.current_path(), "/");
state.push("/users".to_string());
assert_eq!(state.current_path(), "/users");
state.back();
assert_eq!(state.current_path(), "/");Implementations§
Source§impl RouterState
impl RouterState
Return the current navigation ID.
The value is monotonically increasing and is shared across clones of
this state (via Arc<AtomicUsize>).
Start a new navigation and return the new navigation ID
This increments the navigation counter, allowing previous navigations to detect they’ve been superseded and should be cancelled.
Check if a navigation is still current (not cancelled by newer navigation)
Sourcepub fn add_route(&mut self, route: Route)
pub fn add_route(&mut self, route: Route)
Register a route and invalidate the match cache.
Routes are stored in registration order. The first route whose pattern
matches the current path wins during current_match.
Sourcepub fn current_path(&self) -> &str
pub fn current_path(&self) -> &str
Return the current path in the history stack.
Sourcepub fn routes(&self) -> &[Arc<Route>]
pub fn routes(&self) -> &[Arc<Route>]
Return a slice of all registered routes (in registration order).
Sourcepub const fn current_params(&self) -> &RouteParams
pub const fn current_params(&self) -> &RouteParams
Return the current route parameters (used for parameter inheritance in nested routing).
Sourcepub fn set_current_params(&mut self, params: RouteParams)
pub fn set_current_params(&mut self, params: RouteParams)
Update current route parameters
Sourcepub fn current_match(&mut self) -> Option<RouteMatch>
pub fn current_match(&mut self) -> Option<RouteMatch>
Find the RouteMatch for the current path, caching the result.
On a cache miss the registered routes are iterated in order and the first match is stored. Subsequent calls with the same path return the cached value in O(1).
Sourcepub fn current_match_immutable(&self) -> Option<RouteMatch>
pub fn current_match_immutable(&self) -> Option<RouteMatch>
Get current route match without caching (immutable)
Use this when you need to access the current route from a non-mutable context, such as in a GPUI Render implementation.
Sourcepub fn current_route(&self) -> Option<&Arc<Route>>
pub fn current_route(&self) -> Option<&Arc<Route>>
Get the first top-level Route that matches the current path.
With MatchStack architecture, rendering uses GlobalRouter::match_stack().
This method is kept for compatibility — it returns the first registered
route whose pattern matches the current path (exact or prefix).
Sourcepub fn push(&mut self, path: String) -> RouteChangeEvent
pub fn push(&mut self, path: String) -> RouteChangeEvent
Push a new path onto the history stack.
Any forward history (entries after the current cursor) is truncated
before appending, mirroring browser pushState semantics.
Returns a RouteChangeEvent describing the transition.
Sourcepub fn push_with_state(
&mut self,
path: String,
state: HistoryState,
) -> RouteChangeEvent
pub fn push_with_state( &mut self, path: String, state: HistoryState, ) -> RouteChangeEvent
Push a new path with associated HistoryState data.
Allows attaching arbitrary key-value state (scroll position, form data, etc.) to the history entry.
Sourcepub fn replace(&mut self, path: String) -> RouteChangeEvent
pub fn replace(&mut self, path: String) -> RouteChangeEvent
Replace the current history entry in-place without adding a new one.
Useful for redirects where the intermediate path should not appear in the back-button history.
Sourcepub fn replace_with_state(
&mut self,
path: String,
state: HistoryState,
) -> RouteChangeEvent
pub fn replace_with_state( &mut self, path: String, state: HistoryState, ) -> RouteChangeEvent
Replace the current history entry with associated HistoryState data.
Sourcepub fn back(&mut self) -> Option<RouteChangeEvent>
pub fn back(&mut self) -> Option<RouteChangeEvent>
Move the cursor one step back in the history stack.
Returns None if already at the oldest entry.
Sourcepub fn forward(&mut self) -> Option<RouteChangeEvent>
pub fn forward(&mut self) -> Option<RouteChangeEvent>
Move the cursor one step forward in the history stack.
Returns None if already at the newest entry.
Sourcepub const fn can_go_back(&self) -> bool
pub const fn can_go_back(&self) -> bool
Return true if back would succeed.
Sourcepub fn can_go_forward(&self) -> bool
pub fn can_go_forward(&self) -> bool
Return true if forward would succeed.
Sourcepub fn peek_back_path(&self) -> Option<&str>
pub fn peek_back_path(&self) -> Option<&str>
Peek at the path we would navigate to on back(), without actually navigating.
Sourcepub fn peek_forward_path(&self) -> Option<&str>
pub fn peek_forward_path(&self) -> Option<&str>
Peek at the path we would navigate to on forward(), without actually navigating.
Sourcepub fn current_entry(&self) -> &HistoryEntry
pub fn current_entry(&self) -> &HistoryEntry
Return a reference to the current HistoryEntry (path + optional state).
Trait Implementations§
Source§impl Clone for RouterState
impl Clone for RouterState
Source§impl Debug for RouterState
impl Debug for RouterState
Auto Trait Implementations§
impl !RefUnwindSafe for RouterState
impl !UnwindSafe for RouterState
impl Freeze for RouterState
impl Send for RouterState
impl Sync for RouterState
impl Unpin for RouterState
impl UnsafeUnpin for RouterState
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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().