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§
source§impl 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§
source§impl Clone for IdbFrozenStateStore
impl Clone for IdbFrozenStateStore
source§fn clone(&self) -> IdbFrozenStateStore
fn clone(&self) -> IdbFrozenStateStore
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more