pub struct IdbFrozenStateStore { /* private fields */ }
Expand description

A frozen state store that uses IndexedDB as a backend. This will only store a single frozen state at a time, removing all previously stored states every time a new one is set.

TODO Browser compatibility information.

Implementations§

source§

impl IdbFrozenStateStore

source

pub async fn new() -> Result<Self, IdbError>

Creates a new store for this origin. If it already exists from a previous visit, the existing one will be interfaced with.

source

pub async fn get(&self) -> Result<Option<String>, IdbError>

Gets the stored frozen state. Be warned that the result of this could be arbitrarily old, or it may have been tampered with by the user (in which case Perseus will either return an error that you can handle or it’ll fall back to the active state). If no state has been stored yet, this will return Ok(None).

source

pub async fn set(&self, frozen_state: &str) -> Result<(), IdbError>

Sets the content to a new frozen state.

source

pub async fn clear(&self) -> Result<(), IdbError>

Clears the stored frozen state entirely and irrecoverably.

source

pub async fn is_persistent() -> Result<bool, IdbError>

Checks if the storage is persistently stored. If it is, the browser isn’t allowed to clear it, the user would have to manually. This doesn’t provide a guarantee that all users who’ve been to your site before will have previous state stored, you should assume that they could well have cleared it manually (or with very stringent privacy settings).

If this returns an error, a recommendation about whether or not to retry will be attached. You generally shouldn’t retry this more than once if there was an error.

For more information about persistent storage on the web, see here.

source

pub async fn request_persistence() -> Result<bool, IdbError>

Requests persistent storage from the browser. In Firefox, the user will be prompted, though in Chrome the browser will automatically accept or deny based on your site’s level of engagement, whether ot not it’s been installed or bookmarked, and whether or not it’s been granted the permission to show notifications. In other words, do NOT assume that this will be accepted, even if you ask the user very nicely. That said, especially in Firefox, you should display a custom notification before this with alert() or similar that explains why your site needs persistent storage for frozen state.

If this returns false, the request was rejected, but you can retry in future (for user experience though, it’s recommended to only do so very sparingly). If this returns an error, a recommendation about whether or not to retry will be attached. You generally shouldn’t retry this more than once if there was an error.

For more information about persistent storage on the web, see here.

Trait Implementations§

source§

impl Clone for IdbFrozenStateStore

source§

fn clone(&self) -> IdbFrozenStateStore

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

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere 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 Twhere 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 Twhere 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.