Struct Gdbm

Source
pub struct Gdbm { /* private fields */ }
Expand description

An open gdbm database.

Note that a lot of the methods take arguments of type impl AsRef<[u8]>. This means you can pass types String, &str, &String, &[u8] directly.

Implementations§

Source§

impl Gdbm

Source

pub fn new( path: impl AsRef<Path>, block_size: u32, flags: Open, mode: u32, ) -> Result<Gdbm, GdbmError>

Open a DBM with location.

mode is the unix mode used when a database is created. See chmod and open.

Source

pub fn store( &self, key: impl AsRef<[u8]>, content: impl AsRef<[u8]>, replace: bool, ) -> Result<bool, GdbmError>

Store a record in the database.

If replace is false, and the key already exists in the database, the record is not stored and false is returned. Otherwise true is returned.

Source

pub fn fetch_data(&self, key: impl AsRef<[u8]>) -> Result<Vec<u8>, GdbmError>

Retrieve a record from the database.

Source

pub fn fetch_string(&self, key: impl AsRef<[u8]>) -> Result<String, GdbmError>

Retrieve a string record from the database.

If it exists, but the content is not a valid UTF-8 string, FromUtf8Error will be returned.

Source

pub fn fetch_cstring(&self, key: impl AsRef<[u8]>) -> Result<String, GdbmError>

Retrieve a string record from the database and strip trailing ‘\0’.

C libraries might store strings with their trailing ‘\0’ byte. This method is like fetch_string but it strips that byte.

Source

pub fn delete(&self, key: impl AsRef<[u8]>) -> Result<bool, GdbmError>

Delete a record from the database.

Returns false if the key was not present, true if it was present and the record was deleted.

Source

pub fn sync(&self)

Source

pub fn exists(&self, key: impl AsRef<[u8]>) -> Result<bool, GdbmError>

Check to see if a record with this key exists in the database

Trait Implementations§

Source§

impl AsRawFd for Gdbm

With locking disabled (if gdbm_open was called with ‘GDBM_NOLOCK’), the user may want to perform their own file locking on the database file in order to prevent multiple writers operating on the same file simultaneously.

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Debug for Gdbm

Source§

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

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

impl Drop for Gdbm

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Gdbm

Auto Trait Implementations§

§

impl Freeze for Gdbm

§

impl RefUnwindSafe for Gdbm

§

impl !Sync for Gdbm

§

impl Unpin for Gdbm

§

impl UnwindSafe for Gdbm

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, 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.