VowBuilder

Struct VowBuilder 

Source
pub struct VowBuilder<T, F, A, Fo> { /* private fields */ }
Expand description

Builder for Vow.

By default, it will:

  • use JSON format 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>

Source

pub const fn new(file: F) -> Self

Create a new blocking builder.

Source

pub fn open(path: impl AsRef<Path>) -> Self

Open a blocking file at the given path.

Source§

impl<T, F> VowBuilder<Nothing<T>, F, Async, Json>

Source

pub const fn new(file: F) -> Self

Create a new async builder.

Source

pub fn open(path: impl AsRef<Path>) -> Self

Open a blocking file at the given path.

Source§

impl<T, F, A, Fo> VowBuilder<Nothing<T>, F, A, Fo>

Source

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.

Source

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>

Source

pub const fn deny_invalid(self) -> Self

When set true, Vow will fail to build if the file already exists and has invalid content.

Source

pub const fn overwrite_local(self) -> Self

Overwrite the file no matter whether it already exists or if it has valid content

Source

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>

Source

pub fn json(self, pretty: bool) -> VowBuilder<T, F, A, Json>

Available on crate feature format-json only.

Output the data in JSON format.

Source§

impl<T, F, A, Fo> VowBuilder<T, F, A, Fo>

Source

pub fn toml(self) -> VowBuilder<T, F, A, Toml>

Available on crate feature format-toml only.

Output the data in JSON format.

Source§

impl<T, F, Fo> VowBuilder<T, F, Async, Fo>
where T: ToOption, F: VowFileAsync, T::Some: Serialize + DeserializeOwned, Fo: ToFormat,

Source

pub async fn build(self) -> VowResult<VowAsync<T::Some, F>>

Build the VowAsync instance.

Source§

impl<T, F, Fo> VowBuilder<T, F, Blocking, Fo>
where T: ToOption, F: VowFile, T::Some: Serialize + DeserializeOwned, Fo: ToFormat,

Source

pub fn build(self) -> VowResult<Vow<T::Some, F>>

Build the Vow instance.

Auto Trait Implementations§

§

impl<T, F, A, Fo> Freeze for VowBuilder<T, F, A, Fo>
where T: Freeze, Fo: Freeze, F: Freeze,

§

impl<T, F, A, Fo> RefUnwindSafe for VowBuilder<T, F, A, Fo>

§

impl<T, F, A, Fo> Send for VowBuilder<T, F, A, Fo>
where T: Send, Fo: Send, F: Send, A: Send,

§

impl<T, F, A, Fo> Sync for VowBuilder<T, F, A, Fo>
where T: Sync, Fo: Sync, F: Sync, A: Sync,

§

impl<T, F, A, Fo> Unpin for VowBuilder<T, F, A, Fo>
where T: Unpin, Fo: Unpin, F: Unpin, A: Unpin,

§

impl<T, F, A, Fo> UnwindSafe for VowBuilder<T, F, A, Fo>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more