Struct Options

Source
pub struct Options { /* private fields */ }
Available on crate feature std only.
Expand description

Options for the append only log.

Implementations§

Source§

impl Options

Source

pub const fn new() -> Self

Create a new Options with the default values.

§Example
use aol::Options;

let opts = Options::new();
Source

pub const fn magic_version(&self) -> u16

Get the external magic.

§Example
use aol::Options;

let opts = Options::new();

assert_eq!(opts.magic_version(), 0);
Source

pub const fn read_only(&self) -> bool

Get whether the append-only log is read-only.

Default is false.

§Example
use aol::Options;

let opts = Options::new();

assert_eq!(opts.read_only(), false);
Source

pub const fn sync(&self) -> bool

Get whether flush the data to disk after write.

Default is true.

§Example
use aol::Options;

let opts = Options::new();

assert_eq!(opts.sync(), true);
Source

pub const fn rewrite_policy(&self) -> RewritePolicy

Get the rewrite policy.

Default is RewritePolicy::All.

§Example
use aol::{Options, RewritePolicy};

let opts = Options::new().with_rewrite_policy(RewritePolicy::Skip(100));

assert_eq!(opts.rewrite_policy(), RewritePolicy::Skip(100));
Source

pub const fn with_magic_version(self, magic_version: u16) -> Self

Set the external magic.

§Example
use aol::Options;

let opts = Options::new().with_magic_version(1);

assert_eq!(opts.magic_version(), 1);
Source

pub const fn with_read_only(self, read_only: bool) -> Self

Set whether the append-only log is read-only.

Default is false.

§Example
use aol::Options;

let opts = Options::new().with_read_only(true);

assert_eq!(opts.read_only(), true);
Source

pub const fn with_sync(self, sync: bool) -> Self

Set whether flush the data to disk after write.

Default is true.

§Example
use aol::Options;

let opts = Options::new().with_sync(false);

assert_eq!(opts.sync(), false);
Source

pub const fn with_rewrite_policy(self, rewrite_policy: RewritePolicy) -> Self

Set the rewrite policy.

Default is RewritePolicy::All.

§Example
use aol::{Options, RewritePolicy};

let opts = Options::new().with_rewrite_policy(RewritePolicy::Skip(100));
Source§

impl Options

Source

pub const fn read(&self) -> bool

Available on non-target_family="wasm" only.

Returns true if the file should be opened with read access.

§Examples
use aol::Options;

let opts = Options::new().with_read(true);
assert_eq!(opts.read(), true);
Source

pub const fn write(&self) -> bool

Available on non-target_family="wasm" only.

Returns true if the file should be opened with write access.

§Examples
use aol::Options;

let opts = Options::new().with_write(true);
assert_eq!(opts.write(), true);
Source

pub const fn append(&self) -> bool

Available on non-target_family="wasm" only.

Returns true if the file should be opened with append access.

§Examples
use aol::Options;

let opts = Options::new().with_append(true);
assert_eq!(opts.append(), true);
Source

pub const fn truncate(&self) -> bool

Available on non-target_family="wasm" only.

Returns true if the file should be opened with truncate access.

§Examples
use aol::Options;

let opts = Options::new().with_truncate(true);
assert_eq!(opts.truncate(), true);
Source

pub const fn create(&self) -> bool

Available on non-target_family="wasm" only.

Returns true if the file should be created if it does not exist.

§Examples
use aol::Options;

let opts = Options::new().with_create(true);
assert_eq!(opts.create(), true);
Source

pub const fn create_new(&self) -> bool

Available on non-target_family="wasm" only.

Returns true if the file should be created if it does not exist and fail if it does.

§Examples
use aol::Options;

let opts = Options::new().with_create_new(true);
assert_eq!(opts.create_new(), true);
Source

pub fn with_read(self, read: bool) -> Self

Available on non-target_family="wasm" only.

Sets the option for read access.

This option, when true, will indicate that the file should be read-able if opened.

§Examples
use aol::Options;

let opts = Options::new().with_read(true);
Source

pub fn with_write(self, write: bool) -> Self

Available on non-target_family="wasm" only.

Sets the option for write access.

This option, when true, will indicate that the file should be write-able if opened.

If the file already exists, any write calls on it will overwrite its contents, without truncating it.

§Examples
use aol::Options;

let opts = Options::new().with_write(true);
Source

pub fn with_append(self, append: bool) -> Self

Available on non-target_family="wasm" only.

Sets the option for the append mode.

This option, when true, means that writes will append to a file instead of overwriting previous contents. Note that setting .write(true).append(true) has the same effect as setting only .append(true).

For most filesystems, the operating system guarantees that all writes are atomic: no writes get mangled because another process writes at the same time.

One maybe obvious note when using append-mode: make sure that all data that belongs together is written to the file in one operation. This can be done by concatenating strings before passing them to write(), or using a buffered writer (with a buffer of adequate size), and calling flush() when the message is complete.

If a file is opened with both read and append access, beware that after opening, and after every write, the position for reading may be set at the end of the file. So, before writing, save the current position (using seek(SeekFrom::Current(opts))), and restore it before the next read.

§Note

This function doesn’t create the file if it doesn’t exist. Use the Options::with_create method to do so.

§Examples
use aol::Options;

let opts = Options::new().with_append(true);
Source

pub fn with_truncate(self, truncate: bool) -> Self

Available on non-target_family="wasm" only.

Sets the option for truncating a previous file.

If a file is successfully opened with this option set it will truncate the file to opts length if it already exists.

The file must be opened with write access for truncate to work.

§Examples
use aol::Options;

let opts = Options::new().with_write(true).with_truncate(true);
Source

pub fn with_create(self, val: bool) -> Self

Available on non-target_family="wasm" only.

Sets the option to create a new file, or open it if it already exists. If the file does not exist, it is created and set the lenght of the file to the given size.

In order for the file to be created, Options::with_write or Options::with_append access must be used.

See also std::fs::write() for a simple function to create a file with some given data.

§Examples
use aol::Options;

let opts = Options::new().with_write(true).with_create(true);
Source

pub fn with_create_new(self, val: bool) -> Self

Available on non-target_family="wasm" only.

Sets the option to create a new file and set the file length to the given value, failing if it already exists.

No file is allowed to exist at the target location, also no (dangling) symlink. In this way, if the call succeeds, the file returned is guaranteed to be new.

This option is useful because it is atomic. Otherwise between checking whether a file exists and creating a new one, the file may have been created by another process (a TOCTOU race condition / attack).

If .with_create_new(true) is set, .with_create() and .with_truncate() are ignored.

The file must be opened with write or append access in order to create a new file.

§Examples
use aol::Options;

let file = Options::new()
  .with_write(true)
  .with_create_new(true);

Trait Implementations§

Source§

impl Clone for Options

Source§

fn clone(&self) -> Options

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Options

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Options

Source§

fn default() -> Self

Returns the default options.

§Example
use aol::Options;

let opts = Options::default();
Source§

impl<'de> Deserialize<'de> for Options

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Options

Source§

fn eq(&self, other: &Options) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Options

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Options

Source§

impl StructuralPartialEq for Options

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoAmong for T

Source§

fn into_among(self, into_left: Option<bool>) -> Among<Self, Self, Self>

Converts self into a Left variant of Among<Self, Self> if into_left is Some(true). Read more
Source§

fn into_among_with<F>(self, into_left: F) -> Among<Self, Self, Self>
where F: FnOnce(&Self) -> Option<bool>,

Converts self into a Left variant of Among<Self, Self> if into_left(&self) returns Some(true). Read more
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,