Struct ord_lmdb_zero::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
sourceimpl DatabaseOptions
impl DatabaseOptions
sourcepub fn new(flags: Flags) -> DatabaseOptions
pub fn new(flags: Flags) -> DatabaseOptions
Creates a new DatabaseOptions
with the given flags, using natural key
and value ordering.
sourcepub fn defaults() -> DatabaseOptions
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.
sourcepub fn sort_keys_as<K: LmdbOrdKey + ?Sized>(&mut self)
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();
sourcepub fn sort_values_as<V: LmdbOrdKey + ?Sized>(&mut self)
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.
sourcepub fn create_map<K: LmdbOrdKey + ?Sized>() -> Self
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.
sourcepub fn create_multimap_unsized<K: LmdbOrdKey + ?Sized, V: LmdbOrdKey + ?Sized>(
) -> Self
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.
sourcepub fn create_multimap<K: LmdbOrdKey + ?Sized, V: LmdbOrdKey + Sized>() -> Self
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
sourceimpl Clone for DatabaseOptions
impl Clone for DatabaseOptions
sourcefn clone(&self) -> DatabaseOptions
fn clone(&self) -> DatabaseOptions
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl RefUnwindSafe for DatabaseOptions
impl Send for DatabaseOptions
impl Sync for DatabaseOptions
impl Unpin for DatabaseOptions
impl UnwindSafe for DatabaseOptions
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<'a, T> DefaultFeatures<'a> for T where
T: 'a + Send + Sync + Clone,
impl<'a, T> DefaultFeatures<'a> for T where
T: 'a + Send + Sync + Clone,
sourcefn clone_boxed(&self) -> Box<dyn DefaultFeatures<'a> + 'a, Global>
fn clone_boxed(&self) -> Box<dyn DefaultFeatures<'a> + 'a, Global>
Clone this value, and then immediately put it into a Box
behind a trait object of this trait. Read more
sourcefn self_address_mut(&mut self) -> *mut ()
fn self_address_mut(&mut self) -> *mut ()
Returns the address of self
. Read more
sourceimpl<'a, T> NonSyncFeatures<'a> for T where
T: 'a + Clone,
impl<'a, T> NonSyncFeatures<'a> for T where
T: 'a + Clone,
sourcefn clone_boxed(&self) -> Box<dyn NonSyncFeatures<'a> + 'a, Global>
fn clone_boxed(&self) -> Box<dyn NonSyncFeatures<'a> + 'a, Global>
Clone this value, and then immediately put it into a Box
behind a trait object of this trait. Read more
sourcefn self_address_mut(&mut self) -> *mut ()
fn self_address_mut(&mut self) -> *mut ()
Returns the address of self
. Read more
sourceimpl<T> SafeBorrow<T> for T where
T: ?Sized,
impl<T> SafeBorrow<T> for T where
T: ?Sized,
sourcefn borrow_replacement(ptr: &T) -> &T
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
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more