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
impl Gdbm
Sourcepub fn new(
path: impl AsRef<Path>,
block_size: u32,
flags: Open,
mode: u32,
) -> Result<Gdbm, GdbmError>
pub fn new( path: impl AsRef<Path>, block_size: u32, flags: Open, mode: u32, ) -> Result<Gdbm, GdbmError>
Sourcepub fn store(
&self,
key: impl AsRef<[u8]>,
content: impl AsRef<[u8]>,
replace: bool,
) -> Result<bool, GdbmError>
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.
Sourcepub fn fetch_data(&self, key: impl AsRef<[u8]>) -> Result<Vec<u8>, GdbmError>
pub fn fetch_data(&self, key: impl AsRef<[u8]>) -> Result<Vec<u8>, GdbmError>
Retrieve a record from the database.
Sourcepub fn fetch_string(&self, key: impl AsRef<[u8]>) -> Result<String, GdbmError>
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.
Sourcepub fn fetch_cstring(&self, key: impl AsRef<[u8]>) -> Result<String, GdbmError>
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.
Sourcepub fn delete(&self, key: impl AsRef<[u8]>) -> Result<bool, GdbmError>
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.
pub fn sync(&self)
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.
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.