Skip to main content

HmrState

Struct HmrState 

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

A serializable bag of preserved state entries.

Each entry is a (key, value) string pair. The caller is responsible for serializing non-string values (numbers, booleans, etc.) to strings before insertion.

§Wire format

{"entries": {"k1": "v1", "k2": "v2"}}

Implementations§

Source§

impl HmrState

Inherent implementation of HmrState.

Source

pub fn new() -> Self

Creates a new empty HmrState.

Source

pub fn from_entries<I>(entries: I) -> Self
where I: IntoIterator<Item = (String, String)>,

Creates an HmrState from an iterator of (key, value) pairs. Later pairs overwrite earlier ones for the same key.

§Arguments
  • I: IntoIterator<Item = (String, String)> - A generic type parameter.
Source

pub fn set<K, V>(&mut self, key: K, value: V)
where K: Into<String>, V: Into<String>,

Sets a key-value pair. Overwrites any existing value for the key.

§Arguments
  • K: Into<String> - A generic type parameter.
  • V: Into<String> - A generic type parameter.
Source

pub fn get(&self, key: &str) -> Option<&str>

Returns the value for the given key, or None.

§Arguments
  • &str - Shared reference to a str.
§Returns
  • Option<str> - The current value (or a snapshot thereof).
Source

pub fn remove(&mut self, key: &str) -> Option<String>

Removes the entry for the given key, returning the previous value if any.

§Arguments
  • &str - Shared reference to a str.
§Returns
  • Option<String> - Some(...) on success, None otherwise.
Source

pub fn clear(&mut self)

Removes every entry.

Source

pub fn len(&self) -> usize

Returns the number of entries.

§Returns
  • usize - The number of items in the collection.
Source

pub fn is_empty(&self) -> bool

Returns true if the state is empty.

§Returns
  • bool - true when the collection is empty.
Source

pub fn contains(&self, key: &str) -> bool

Returns true if the state contains the given key.

§Arguments
  • &str - Shared reference to a str.
§Returns
  • bool - A boolean.
Source

pub fn iter(&self) -> impl Iterator<Item = (&str, &str)>

Returns an iterator over the entries.

§Returns
  • impl Iterator<Item - A impl Iterator<Item value.

Trait Implementations§

Source§

impl Clone for HmrState

Source§

fn clone(&self) -> HmrState

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 Debug for HmrState

Source§

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

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

impl Default for HmrState

Source§

fn default() -> HmrState

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

impl Eq for HmrState

Source§

impl PartialEq for HmrState

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for HmrState

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> AnySend for T
where T: Any + Send,

Source§

impl<T> AnySendClone for T
where T: Any + Send + Clone,

Source§

impl<T> AnySendSync for T
where T: Any + Send + Sync,

Source§

impl<T> AnySendSyncClone for T
where T: Any + Send + Sync + Clone,

Source§

impl<T> AnySync for T
where T: Any + Sync,

Source§

impl<T> AnySyncClone for T
where T: Any + Sync + Clone,

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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, <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.