Struct DatabaseOptions

Source
pub struct DatabaseOptions {
    pub flags: Flags,
    /* private fields */
}
Expand description

Describes the options used for creating or opening a database.

Fields§

§flags: Flags

The integer flags to pass to LMDB

Implementations§

Source§

impl DatabaseOptions

Source

pub fn new(flags: Flags) -> DatabaseOptions

Creates a new DatabaseOptions with the given flags, using natural key and value ordering.

Source

pub fn defaults() -> DatabaseOptions

Synonym for DatabaseOptions::new(db::Flags::empty()).

Note that this does not even have db::CREATE set. This is most useful when opening the anonymous default database.

Source

pub fn sort_keys_as<K: LmdbOrdKey + ?Sized>(&mut self)

Sorts keys in the database by interpreting them as K and using their comparison order. Keys which fail to convert are considered equal.

The comparison function is called whenever it is necessary to compare a key specified by the application with a key currently stored in the database. If no comparison function is specified, and no special key flags were specified in the options, the keys are compared lexically, with shorter keys collating before longer keys.

§Warning

This function must be called before any data access functions are used, otherwise data corruption may occur. The same comparison function must be used by every program accessing the database, every time the database is used.

§Example
#[repr(C, packed)]
#[derive(Clone,Copy,Debug,PartialEq,Eq,PartialOrd,Ord)]
struct MyStruct {
  x: i32,
  y: i32,
}
unsafe impl lmdb::traits::LmdbRaw for MyStruct { }
unsafe impl lmdb::traits::LmdbOrdKey for MyStruct { }

fn my(x: i32, y: i32) -> MyStruct {
  MyStruct { x: x, y: y }
}

let mut opts = lmdb::DatabaseOptions::new(lmdb::db::CREATE);
opts.sort_keys_as::<MyStruct>();
let db = lmdb::Database::open(&env, Some("example"), &opts).unwrap();
let txn = lmdb::WriteTransaction::new(&env).unwrap();
{
  let mut access = txn.access();
  let f = lmdb::put::Flags::empty();
  access.put(&db, &my(0, 0), "origin", f).unwrap();
  access.put(&db, &my(-1, 0), "x=-1", f).unwrap();
  access.put(&db, &my(1, 0), "x=+1", f).unwrap();
  access.put(&db, &my(0, -1), "y=-1", f).unwrap();

  let mut cursor = txn.cursor(&db).unwrap();
  // The keys are sorted by the Rust-derived comparison. The default
  // byte-string comparison would have resulted in (0,0), (0,-1),
  // (1,0), (-1,0).
  assert_eq!((&my(-1, 0), "x=-1"), cursor.first(&access).unwrap());
  assert_eq!((&my(0, -1), "y=-1"), cursor.next(&access).unwrap());
  assert_eq!((&my(0, 0), "origin"), cursor.next(&access).unwrap());
  assert_eq!((&my(1, 0), "x=+1"), cursor.next(&access).unwrap());
}
txn.commit().unwrap();
Source

pub fn sort_values_as<V: LmdbOrdKey + ?Sized>(&mut self)

Sorts duplicate values in the database by interpreting them as V and using their comparison order. Values which fail to convert are considered equal.

This comparison function is called whenever it is necessary to compare a data item specified by the application with a data item currently stored in the database. This function only takes effect if the database iss opened with the DUPSORT flag. If no comparison function is specified, and no special key flags were specified in the flags of these options, the data items are compared lexically, with shorter items collating before longer items.

§Warning

This function must be called before any data access functions are used, otherwise data corruption may occur. The same comparison function must be used by every program accessing the database, every time the database is used.

Source

pub fn create_map<K: LmdbOrdKey + ?Sized>() -> Self

Concisely creates a DatabaseOptions to configure a database to have a 1:1 mapping using the given key type.

The flags always have db::CREATE set. If K is understood by LMDB as an integer, db::INTEGERKEY is set. Otherwise, unless K sorts properly via byte-string comparison, sort_keys_as is called to configure the database to use K’s Ord implementation.

Source

pub fn create_multimap_unsized<K: LmdbOrdKey + ?Sized, V: LmdbOrdKey + ?Sized>() -> Self

Concisely creates a DatabaseOptions to configure a database to have a 1:M mapping using the given key and unsized value types.

The flags are configured as described with create_map with db::DUPSORT added. If V is understood by LMDB as an integer, INTEGERDUP is set. Otherwise, if V is not byte-string comparable, sort_values_as is used to order values by V’s Ord implementation.

Source

pub fn create_multimap<K: LmdbOrdKey + ?Sized, V: LmdbOrdKey + Sized>() -> Self

Concisely creates a DatabaseOptions to configure a database to have a 1:M mapping using the given key and fixed-size value types.

This is the same as create_multimap_unsized, except that DUPFIXED is additionally set unconditionally.

Trait Implementations§

Source§

impl Clone for DatabaseOptions

Source§

fn clone(&self) -> DatabaseOptions

Returns a duplicate 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 DatabaseOptions

Source§

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

Formats the value using the given formatter. Read more

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<'a, T> DefaultFeatures<'a> for T
where T: 'a + Send + Sync + Clone,

Source§

fn clone_boxed(&self) -> Box<dyn DefaultFeatures<'a>>

Clone this value, and then immediately put it into a Box behind a trait object of this trait.
Source§

fn self_address_mut(&mut self) -> *mut ()

Returns the address of self. 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<'a, T> NonSyncFeatures<'a> for T
where T: 'a + Clone,

Source§

fn clone_boxed(&self) -> Box<dyn NonSyncFeatures<'a>>

Clone this value, and then immediately put it into a Box behind a trait object of this trait.
Source§

fn self_address_mut(&mut self) -> *mut ()

Returns the address of self. Read more
Source§

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

Source§

fn borrow_replacement(ptr: &T) -> &T

Given ptr, which was obtained from a prior call to Self::borrow(), return a value with the same nominal lifetime which is guaranteed to survive mutations to Self. 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.