Struct perseus::state::IdbFrozenStateStore
source · [−]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
sourceimpl IdbFrozenStateStore
impl IdbFrozenStateStore
sourcepub async fn new() -> Result<Self, IdbError>
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.
sourcepub async fn get(&self) -> Result<Option<String>, IdbError>
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)
.
sourcepub async fn set(&self, frozen_state: &str) -> Result<(), IdbError>
pub async fn set(&self, frozen_state: &str) -> Result<(), IdbError>
Sets the content to a new frozen state.
sourcepub async fn clear(&self) -> Result<(), IdbError>
pub async fn clear(&self) -> Result<(), IdbError>
Clears the stored frozen state entirely and irrecoverably.
sourcepub async fn is_persistent() -> Result<bool, IdbError>
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.
sourcepub async fn request_persistence() -> Result<bool, IdbError>
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
sourceimpl Clone for IdbFrozenStateStore
impl Clone for IdbFrozenStateStore
sourcefn clone(&self) -> IdbFrozenStateStore
fn clone(&self) -> IdbFrozenStateStore
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl RefUnwindSafe for IdbFrozenStateStore
impl !Send for IdbFrozenStateStore
impl !Sync for IdbFrozenStateStore
impl Unpin for IdbFrozenStateStore
impl UnwindSafe for IdbFrozenStateStore
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more