pub struct PrivateDocument { /* private fields */ }Available on non-
target_family=wasm only.Expand description
One document at one path. The byte ceiling is the caller’s: a document that outgrows it is a bug or a tampered file, never something to parse.
Implementations§
Source§impl PrivateDocument
impl PrivateDocument
pub fn new(path: impl Into<PathBuf>, maximum_bytes: u64) -> Self
pub fn path(&self) -> &Path
Sourcepub fn read<T: DeserializeOwned>(&self) -> Result<Option<T>, DocumentError>
pub fn read<T: DeserializeOwned>(&self) -> Result<Option<T>, DocumentError>
The parsed document, or None when nothing is written there yet.
Creates the containing directory, so a first read leaves a private
home for the first write.
Sourcepub fn prepare<T: Serialize>(
&self,
value: &T,
) -> Result<PreparedWrite, DocumentError>
pub fn prepare<T: Serialize>( &self, value: &T, ) -> Result<PreparedWrite, DocumentError>
Serializes and stages the write. Nothing is visible at the path until
PreparedWrite::commit.
Sourcepub fn claim(&self) -> Result<bool, DocumentError>
pub fn claim(&self) -> Result<bool, DocumentError>
Creates the document empty, and only if nothing is there yet.
false when something already is.
The filesystem decides, not the caller: a name that folds onto an existing one — a different case, a different unicode normalization — is refused here, which no comparison of names could do portably.
Sourcepub fn remove(&self) -> Result<bool, DocumentError>
pub fn remove(&self) -> Result<bool, DocumentError>
Deletes the document. false when there was nothing there.
Auto Trait Implementations§
impl Freeze for PrivateDocument
impl RefUnwindSafe for PrivateDocument
impl Send for PrivateDocument
impl Sync for PrivateDocument
impl Unpin for PrivateDocument
impl UnsafeUnpin for PrivateDocument
impl UnwindSafe for PrivateDocument
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more