pub struct VowBuilder<T, F, A, Fo> { /* private fields */ }Expand description
Builder for Vow.
By default, it will:
- use
JSONformat without pretty printing. - not overwrite the file if it already exists and has valid content.
- not fail on (deny) invalid content (instead, overwrite it silently).
It is usually recommended to use Vow::builder or Vow::open and its async counterparts to create a new builder.
§Example
use vow::VowBuilder;
use serde::{Deserialize, Serialize};
use std::fs::File;
#[derive(Serialize, Deserialize)]
struct Data {
value: i32,
}
let file = File::create("data.json").unwrap();
let vow = VowBuilder::new(file)
.json()
.pretty()
.default(Data { value: 42 })
.deny_invalid()
.overwrite_local()
.build();Implementations§
Source§impl<T, F> VowBuilder<Nothing<T>, F, Blocking, Json>
impl<T, F> VowBuilder<Nothing<T>, F, Blocking, Json>
Source§impl<T, F> VowBuilder<Nothing<T>, F, Async, Json>
impl<T, F> VowBuilder<Nothing<T>, F, Async, Json>
Source§impl<T, F, A, Fo> VowBuilder<Nothing<T>, F, A, Fo>
impl<T, F, A, Fo> VowBuilder<Nothing<T>, F, A, Fo>
Sourcepub fn with_type<U>(self) -> VowBuilder<Nothing<U>, F, A, Fo>
pub fn with_type<U>(self) -> VowBuilder<Nothing<U>, F, A, Fo>
Set the type of the value without providing anything concrete.
This is useful when you know there’s existsing value stored in file and its type, so we can just retrieve it during initialization.
Sourcepub fn default<U>(self, value: U) -> VowBuilder<Just<U>, F, A, Fo>
pub fn default<U>(self, value: U) -> VowBuilder<Just<U>, F, A, Fo>
Set the default value in case the file is empty or has invalid content.
Source§impl<T, F, A, Fo> VowBuilder<T, F, A, Fo>
impl<T, F, A, Fo> VowBuilder<T, F, A, Fo>
Sourcepub const fn deny_invalid(self) -> Self
pub const fn deny_invalid(self) -> Self
When set true, Vow will fail to build if the file already exists and has invalid content.
Sourcepub const fn overwrite_local(self) -> Self
pub const fn overwrite_local(self) -> Self
Overwrite the file no matter whether it already exists or if it has valid content
Sourcepub const fn keep_local(self) -> Self
pub const fn keep_local(self) -> Self
Keep the file content unless it doesn’t exist or contains invalid content
Source§impl<T, F, A, Fo> VowBuilder<T, F, A, Fo>
impl<T, F, A, Fo> VowBuilder<T, F, A, Fo>
Sourcepub fn json(self, pretty: bool) -> VowBuilder<T, F, A, Json>
Available on crate feature format-json only.
pub fn json(self, pretty: bool) -> VowBuilder<T, F, A, Json>
format-json only.Output the data in JSON format.
Source§impl<T, F, A, Fo> VowBuilder<T, F, A, Fo>
impl<T, F, A, Fo> VowBuilder<T, F, A, Fo>
Sourcepub fn toml(self) -> VowBuilder<T, F, A, Toml>
Available on crate feature format-toml only.
pub fn toml(self) -> VowBuilder<T, F, A, Toml>
format-toml only.Output the data in JSON format.
Source§impl<T, F, Fo> VowBuilder<T, F, Async, Fo>
impl<T, F, Fo> VowBuilder<T, F, Async, Fo>
Auto Trait Implementations§
impl<T, F, A, Fo> Freeze for VowBuilder<T, F, A, Fo>
impl<T, F, A, Fo> RefUnwindSafe for VowBuilder<T, F, A, Fo>
impl<T, F, A, Fo> Send for VowBuilder<T, F, A, Fo>
impl<T, F, A, Fo> Sync for VowBuilder<T, F, A, Fo>
impl<T, F, A, Fo> Unpin for VowBuilder<T, F, A, Fo>
impl<T, F, A, Fo> UnwindSafe for VowBuilder<T, F, A, Fo>
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