pub struct StateRestorer<SP>
where SP: ShMemProvider,
{ /* private fields */ }
Expand description

A StateRestorer saves and restores bytes to a shared map. If the state gets larger than the preallocated ShMem shared map, it will instead write to disk, and store the file name into the map. Writing to StateRestorer multiple times is not allowed.

Implementations§

source§

impl<SP> StateRestorer<SP>
where SP: ShMemProvider,

source

pub fn mapsize(&self) -> usize

Get the map size backing this StateRestorer.

source

pub fn write_to_env(&self, env_name: &str) -> Result<(), Error>

Writes this StateRestorer to env variable, to be restored later

source

pub fn from_env(shmem_provider: &mut SP, env_name: &str) -> Result<Self, Error>

Create a StateRestorer from env variable name

source

pub fn new(shmem: SP::ShMem) -> Self

Create a new StateRestorer.

source

pub fn save<S>(&mut self, state: &S) -> Result<(), Error>
where S: Serialize,

Saves a state to the connected ShMem, or a tmpfile, if its serialized size get too large.

source

pub fn reset(&mut self)

Reset this StateRestorer to an empty state.

source

pub fn send_exiting(&mut self)

When called from a child, informs the restarter/parent process that it should no longer respawn the child.

source

pub fn wants_to_exit(&self) -> bool

Returns true, if Self::send_exiting was called on this StateRestorer last. This should be checked in the parent before deciding to restore the client.

source

pub fn has_content(&self) -> bool

Returns true, if this StateRestorer has contents.

source

pub fn restore<S>(&self) -> Result<Option<S>, Error>

Restores the contents saved in this StateRestorer, if any are available. Can only be read once.

Trait Implementations§

source§

impl<SP> Clone for StateRestorer<SP>
where SP: ShMemProvider + Clone, SP::ShMem: Clone,

source§

fn clone(&self) -> StateRestorer<SP>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<SP> Debug for StateRestorer<SP>
where SP: ShMemProvider + Debug, SP::ShMem: Debug,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<SP> RefUnwindSafe for StateRestorer<SP>

§

impl<SP> !Send for StateRestorer<SP>

§

impl<SP> !Sync for StateRestorer<SP>

§

impl<SP> Unpin for StateRestorer<SP>
where <SP as ShMemProvider>::ShMem: Unpin,

§

impl<SP> UnwindSafe for StateRestorer<SP>

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<Tail, T> Prepend<T> for Tail

§

type PreprendResult = Tail

The Resulting TupleList, of an Prepend::prepend() call, including the prepended entry.
source§

fn prepend(self, value: T) -> (T, <Tail as Prepend<T>>::PreprendResult)

Prepend a value to this tuple, returning a new tuple with prepended value.
source§

impl<T> ToOwned for T
where T: Clone,

§

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

§

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

§

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.