Skip to main content

NavBackStackEntry

Struct NavBackStackEntry 

Source
pub struct NavBackStackEntry<R: Clone + 'static> { /* private fields */ }
Expand description

One visit on a NavController’s back stack — Android’s NavBackStackEntry.

Its route carries the screen’s arguments. Other screens leave it values with Self::set_result, as Android’s savedStateHandle does, and its screen reads them with Self::result. A screen returns a result to the one beneath it this way:

use cranpose_navigation::NavController;

#[derive(Clone, PartialEq)]
enum Screen {
    Home,
    PickColor,
}

#[derive(Clone)]
struct Picked(u32);

fn pick(nav: NavController<Screen>, color: u32) {
    if let Some(home) = nav.previous_back_stack_entry() {
        home.set_result(Picked(color));
    }
    nav.pop_back_stack();
}

// In the home screen, while composing:
fn picked(nav: NavController<Screen>) -> Option<u32> {
    let Picked(color) = nav.composing_entry()?.result::<Picked>()?;
    Some(color)
}

The type of a value is its key, so an entry holds one value of each type; a newtype per result keeps two results of one type apart. Results live in memory: a popped entry drops them, and a restored back stack starts without them. A screen that shows a result for longer takes it into its own saved state, such as rememberSaveable.

Implementations§

Source§

impl<R: Clone + PartialEq + 'static> NavBackStackEntry<R>

Source

pub fn route(&self) -> Option<R>

The entry’s route, with the screen’s arguments; None once it is popped. It does not subscribe the caller: an entry keeps its route.

Source

pub fn result<T: Clone + 'static>(&self) -> Option<T>

The value of type T that a screen left for this entry. Reading it in a composable recomposes that composable when the value changes — Android’s savedStateHandle.getStateFlow(key).

Source

pub fn set_result<T: 'static>(&self, value: T)

Leaves value for this entry, in place of its earlier value of type T — Android’s savedStateHandle[key] = value. Does nothing once the entry is popped.

Source

pub fn take_result<T: Clone + 'static>(&self) -> Option<T>

Removes the value of type T and returns it — Android’s savedStateHandle.remove(key). A screen calls it once it has acted on a result, from an effect or a callback.

Trait Implementations§

Source§

impl<R: Clone + 'static> Clone for NavBackStackEntry<R>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<R: Clone + 'static> Copy for NavBackStackEntry<R>

Source§

impl<R: Clone + 'static> PartialEq for NavBackStackEntry<R>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

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<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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.