Struct heed::Database

source ·
pub struct Database<KC, DC, C = DefaultComparator> { /* private fields */ }
Expand description

A typed database that accepts only the types it was created with.

§Example: Iterate over databases entries

In this example we store numbers in big endian this way those are ordered. Thanks to their bytes representation, heed is able to iterate over them from the lowest to the highest.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI64 = I64<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI64, Unit> = env.create_database(&mut wtxn, Some("big-endian-iter"))?;

db.put(&mut wtxn, &68, &())?;
db.put(&mut wtxn, &35, &())?;
db.put(&mut wtxn, &0, &())?;
db.put(&mut wtxn, &42, &())?;

// you can iterate over database entries in order
let rets: Result<_, _> = db.iter(&wtxn)?.collect();
let rets: Vec<(i64, _)> = rets?;

let expected = vec![
    (0, ()),
    (35, ()),
    (42, ()),
    (68, ()),
];

assert_eq!(rets, expected);
wtxn.commit()?;

§Example: Iterate over and delete ranges of entries

Discern also support ranges and ranges deletions. Same configuration as above, numbers are ordered, therefore it is safe to specify a range and be able to iterate over and/or delete it.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI64 = I64<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI64, Unit> = env.create_database(&mut wtxn, Some("big-endian-iter"))?;

db.put(&mut wtxn, &0, &())?;
db.put(&mut wtxn, &68, &())?;
db.put(&mut wtxn, &35, &())?;
db.put(&mut wtxn, &42, &())?;

// you can iterate over ranges too!!!
let range = 35..=42;
let rets: Result<_, _> = db.range(&wtxn, &range)?.collect();
let rets: Vec<(i64, _)> = rets?;

let expected = vec![
    (35, ()),
    (42, ()),
];

assert_eq!(rets, expected);

// even delete a range of keys
let range = 35..=42;
let deleted: usize = db.delete_range(&mut wtxn, &range)?;

let rets: Result<_, _> = db.iter(&wtxn)?.collect();
let rets: Vec<(i64, _)> = rets?;

let expected = vec![
    (0, ()),
    (68, ()),
];

assert_eq!(deleted, 2);
assert_eq!(rets, expected);

wtxn.commit()?;

Implementations§

source§

impl<KC, DC, C> Database<KC, DC, C>

source

pub fn get<'a, 'txn>( &self, txn: &'txn RoTxn<'_>, key: &'a KC::EItem, ) -> Result<Option<DC::DItem>>
where KC: BytesEncode<'a>, DC: BytesDecode<'txn>,

Retrieves the value associated with a key.

If the key does not exist, then None is returned.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32= U32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<Str, BEI32> = env.create_database(&mut wtxn, Some("get-i32"))?;

db.put(&mut wtxn, "i-am-forty-two", &42)?;
db.put(&mut wtxn, "i-am-twenty-seven", &27)?;

let ret = db.get(&wtxn, "i-am-forty-two")?;
assert_eq!(ret, Some(42));

let ret = db.get(&wtxn, "i-am-twenty-one")?;
assert_eq!(ret, None);

wtxn.commit()?;
source

pub fn get_duplicates<'a, 'txn>( &self, txn: &'txn RoTxn<'_>, key: &'a KC::EItem, ) -> Result<Option<RoIter<'txn, KC, DC, MoveOnCurrentKeyDuplicates>>>
where KC: BytesEncode<'a>,

Returns an iterator over all of the values of a single key.

You can make this iterator Sendable between threads by using the read-txn-no-tls crate feature.

use heed::types::*;
use heed::byteorder::BigEndian;

type BEI64 = I64<BigEndian>;

let mut wtxn = env.write_txn()?;
let db = env.database_options()
    .types::<BEI64, BEI64>()
    .flags(DatabaseFlags::DUP_SORT)
    .name("dup-sort")
    .create(&mut wtxn)?;

db.put(&mut wtxn, &68, &120)?;
db.put(&mut wtxn, &68, &121)?;
db.put(&mut wtxn, &68, &122)?;
db.put(&mut wtxn, &68, &123)?;
db.put(&mut wtxn, &92, &32)?;
db.put(&mut wtxn, &35, &120)?;
db.put(&mut wtxn, &0, &120)?;
db.put(&mut wtxn, &42, &120)?;

let mut iter = db.get_duplicates(&wtxn, &68)?.expect("the key exists");
assert_eq!(iter.next().transpose()?, Some((68, 120)));
assert_eq!(iter.next().transpose()?, Some((68, 121)));
assert_eq!(iter.next().transpose()?, Some((68, 122)));
assert_eq!(iter.next().transpose()?, Some((68, 123)));
assert_eq!(iter.next().transpose()?, None);
drop(iter);

let mut iter = db.get_duplicates(&wtxn, &68)?.expect("the key exists");
assert_eq!(iter.last().transpose()?, Some((68, 123)));

wtxn.commit()?;
source

pub fn get_lower_than<'a, 'txn>( &self, txn: &'txn RoTxn<'_>, key: &'a KC::EItem, ) -> Result<Option<(KC::DItem, DC::DItem)>>
where KC: BytesEncode<'a> + BytesDecode<'txn>, DC: BytesDecode<'txn>,

Retrieves the key/value pair lower than the given one in this database.

If the database if empty or there is no key lower than the given one, then None is returned.

Comparisons are made by using the bytes representation of the key.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEU32 = U32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db = env.create_database::<BEU32, Unit>(&mut wtxn, Some("get-lt-u32"))?;

db.put(&mut wtxn, &27, &())?;
db.put(&mut wtxn, &42, &())?;
db.put(&mut wtxn, &43, &())?;

let ret = db.get_lower_than(&wtxn, &4404)?;
assert_eq!(ret, Some((43, ())));

let ret = db.get_lower_than(&wtxn, &43)?;
assert_eq!(ret, Some((42, ())));

let ret = db.get_lower_than(&wtxn, &27)?;
assert_eq!(ret, None);

wtxn.commit()?;
source

pub fn get_lower_than_or_equal_to<'a, 'txn>( &self, txn: &'txn RoTxn<'_>, key: &'a KC::EItem, ) -> Result<Option<(KC::DItem, DC::DItem)>>
where KC: BytesEncode<'a> + BytesDecode<'txn>, DC: BytesDecode<'txn>,

Retrieves the key/value pair lower than or equal to the given one in this database.

If the database if empty or there is no key lower than or equal to the given one, then None is returned.

Comparisons are made by using the bytes representation of the key.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEU32 = U32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db = env.create_database::<BEU32, Unit>(&mut wtxn, Some("get-lt-u32"))?;

db.put(&mut wtxn, &27, &())?;
db.put(&mut wtxn, &42, &())?;
db.put(&mut wtxn, &43, &())?;

let ret = db.get_lower_than_or_equal_to(&wtxn, &4404)?;
assert_eq!(ret, Some((43, ())));

let ret = db.get_lower_than_or_equal_to(&wtxn, &43)?;
assert_eq!(ret, Some((43, ())));

let ret = db.get_lower_than_or_equal_to(&wtxn, &26)?;
assert_eq!(ret, None);

wtxn.commit()?;
source

pub fn get_greater_than<'a, 'txn>( &self, txn: &'txn RoTxn<'_>, key: &'a KC::EItem, ) -> Result<Option<(KC::DItem, DC::DItem)>>
where KC: BytesEncode<'a> + BytesDecode<'txn>, DC: BytesDecode<'txn>,

Retrieves the key/value pair greater than the given one in this database.

If the database if empty or there is no key greater than the given one, then None is returned.

Comparisons are made by using the bytes representation of the key.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEU32 = U32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db = env.create_database::<BEU32, Unit>(&mut wtxn, Some("get-lt-u32"))?;

db.put(&mut wtxn, &27, &())?;
db.put(&mut wtxn, &42, &())?;
db.put(&mut wtxn, &43, &())?;

let ret = db.get_greater_than(&wtxn, &0)?;
assert_eq!(ret, Some((27, ())));

let ret = db.get_greater_than(&wtxn, &42)?;
assert_eq!(ret, Some((43, ())));

let ret = db.get_greater_than(&wtxn, &43)?;
assert_eq!(ret, None);

wtxn.commit()?;
source

pub fn get_greater_than_or_equal_to<'a, 'txn>( &self, txn: &'txn RoTxn<'_>, key: &'a KC::EItem, ) -> Result<Option<(KC::DItem, DC::DItem)>>
where KC: BytesEncode<'a> + BytesDecode<'txn>, DC: BytesDecode<'txn>,

Retrieves the key/value pair greater than or equal to the given one in this database.

If the database if empty or there is no key greater than or equal to the given one, then None is returned.

Comparisons are made by using the bytes representation of the key.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEU32 = U32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db = env.create_database::<BEU32, Unit>(&mut wtxn, Some("get-lt-u32"))?;

db.put(&mut wtxn, &27, &())?;
db.put(&mut wtxn, &42, &())?;
db.put(&mut wtxn, &43, &())?;

let ret = db.get_greater_than_or_equal_to(&wtxn, &0)?;
assert_eq!(ret, Some((27, ())));

let ret = db.get_greater_than_or_equal_to(&wtxn, &42)?;
assert_eq!(ret, Some((42, ())));

let ret = db.get_greater_than_or_equal_to(&wtxn, &44)?;
assert_eq!(ret, None);

wtxn.commit()?;
source

pub fn first<'txn>( &self, txn: &'txn RoTxn<'_>, ) -> Result<Option<(KC::DItem, DC::DItem)>>
where KC: BytesDecode<'txn>, DC: BytesDecode<'txn>,

Retrieves the first key/value pair of this database.

If the database if empty, then None is returned.

Comparisons are made by using the bytes representation of the key.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI32, Str> = env.create_database(&mut wtxn, Some("first-i32"))?;

db.put(&mut wtxn, &42, "i-am-forty-two")?;
db.put(&mut wtxn, &27, "i-am-twenty-seven")?;

let ret = db.first(&wtxn)?;
assert_eq!(ret, Some((27, "i-am-twenty-seven")));

wtxn.commit()?;
source

pub fn last<'txn>( &self, txn: &'txn RoTxn<'_>, ) -> Result<Option<(KC::DItem, DC::DItem)>>
where KC: BytesDecode<'txn>, DC: BytesDecode<'txn>,

Retrieves the last key/value pair of this database.

If the database if empty, then None is returned.

Comparisons are made by using the bytes representation of the key.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI32, Str> = env.create_database(&mut wtxn, Some("last-i32"))?;

db.put(&mut wtxn, &42, "i-am-forty-two")?;
db.put(&mut wtxn, &27, "i-am-twenty-seven")?;

let ret = db.last(&wtxn)?;
assert_eq!(ret, Some((42, "i-am-forty-two")));

wtxn.commit()?;
source

pub fn len(&self, txn: &RoTxn<'_>) -> Result<u64>

Returns the number of elements in this database.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI32, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?;

db.put(&mut wtxn, &42, "i-am-forty-two")?;
db.put(&mut wtxn, &27, "i-am-twenty-seven")?;
db.put(&mut wtxn, &13, "i-am-thirteen")?;
db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?;

let ret = db.len(&wtxn)?;
assert_eq!(ret, 4);

db.delete(&mut wtxn, &27)?;

let ret = db.len(&wtxn)?;
assert_eq!(ret, 3);

wtxn.commit()?;
source

pub fn is_empty(&self, txn: &RoTxn<'_>) -> Result<bool>

Returns true if and only if this database is empty.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI32, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?;

db.put(&mut wtxn, &42, "i-am-forty-two")?;
db.put(&mut wtxn, &27, "i-am-twenty-seven")?;
db.put(&mut wtxn, &13, "i-am-thirteen")?;
db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?;

let ret = db.is_empty(&wtxn)?;
assert_eq!(ret, false);

db.clear(&mut wtxn)?;

let ret = db.is_empty(&wtxn)?;
assert_eq!(ret, true);

wtxn.commit()?;
source

pub fn stat(&self, txn: &RoTxn<'_>) -> Result<DatabaseStat>

Returns some statistics for this database.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI32, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?;

db.put(&mut wtxn, &42, "i-am-forty-two")?;
db.put(&mut wtxn, &27, "i-am-twenty-seven")?;
db.put(&mut wtxn, &13, "i-am-thirteen")?;
db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?;

let stat = db.stat(&wtxn)?;
assert_eq!(stat.depth, 1);
assert_eq!(stat.branch_pages, 0);
assert_eq!(stat.leaf_pages, 1);
assert_eq!(stat.overflow_pages, 0);
assert_eq!(stat.entries, 4);

wtxn.commit()?;
source

pub fn iter<'txn>(&self, txn: &'txn RoTxn<'_>) -> Result<RoIter<'txn, KC, DC>>

Return a lexicographically ordered iterator of all key-value pairs in this database.

You can make this iterator Sendable between threads by using the read-txn-no-tls crate feature.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI32, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?;

db.put(&mut wtxn, &42, "i-am-forty-two")?;
db.put(&mut wtxn, &27, "i-am-twenty-seven")?;
db.put(&mut wtxn, &13, "i-am-thirteen")?;

let mut iter = db.iter(&wtxn)?;
assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen")));
assert_eq!(iter.next().transpose()?, Some((27, "i-am-twenty-seven")));
assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two")));
assert_eq!(iter.next().transpose()?, None);

drop(iter);
wtxn.commit()?;
source

pub fn iter_mut<'txn>( &self, txn: &'txn mut RwTxn<'_>, ) -> Result<RwIter<'txn, KC, DC>>

Return a mutable lexicographically ordered iterator of all key-value pairs in this database.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI32, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?;

db.put(&mut wtxn, &42, "i-am-forty-two")?;
db.put(&mut wtxn, &27, "i-am-twenty-seven")?;
db.put(&mut wtxn, &13, "i-am-thirteen")?;

let mut iter = db.iter_mut(&mut wtxn)?;
assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen")));
let ret = unsafe { iter.del_current()? };
assert!(ret);

assert_eq!(iter.next().transpose()?, Some((27, "i-am-twenty-seven")));
assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two")));
let ret = unsafe { iter.put_current(&42, "i-am-the-new-forty-two")? };
assert!(ret);

assert_eq!(iter.next().transpose()?, None);

drop(iter);

let ret = db.get(&wtxn, &13)?;
assert_eq!(ret, None);

let ret = db.get(&wtxn, &42)?;
assert_eq!(ret, Some("i-am-the-new-forty-two"));

wtxn.commit()?;
source

pub fn rev_iter<'txn>( &self, txn: &'txn RoTxn<'_>, ) -> Result<RoRevIter<'txn, KC, DC>>

Return a reversed lexicographically ordered iterator of all key-value pairs in this database.

You can make this iterator Sendable between threads by using the read-txn-no-tls crate feature.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI32, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?;

db.put(&mut wtxn, &42, "i-am-forty-two")?;
db.put(&mut wtxn, &27, "i-am-twenty-seven")?;
db.put(&mut wtxn, &13, "i-am-thirteen")?;

let mut iter = db.rev_iter(&wtxn)?;
assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two")));
assert_eq!(iter.next().transpose()?, Some((27, "i-am-twenty-seven")));
assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen")));
assert_eq!(iter.next().transpose()?, None);

drop(iter);
wtxn.commit()?;
source

pub fn rev_iter_mut<'txn>( &self, txn: &'txn mut RwTxn<'_>, ) -> Result<RwRevIter<'txn, KC, DC>>

Return a mutable reversed lexicographically ordered iterator of all key-value
pairs in this database.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI32, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?;

db.put(&mut wtxn, &42, "i-am-forty-two")?;
db.put(&mut wtxn, &27, "i-am-twenty-seven")?;
db.put(&mut wtxn, &13, "i-am-thirteen")?;

let mut iter = db.rev_iter_mut(&mut wtxn)?;
assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two")));
let ret = unsafe { iter.del_current()? };
assert!(ret);

assert_eq!(iter.next().transpose()?, Some((27, "i-am-twenty-seven")));
assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen")));
let ret = unsafe { iter.put_current(&13, "i-am-the-new-thirteen")? };
assert!(ret);

assert_eq!(iter.next().transpose()?, None);

drop(iter);

let ret = db.get(&wtxn, &42)?;
assert_eq!(ret, None);

let ret = db.get(&wtxn, &13)?;
assert_eq!(ret, Some("i-am-the-new-thirteen"));

wtxn.commit()?;
source

pub fn range<'a, 'txn, R>( &self, txn: &'txn RoTxn<'_>, range: &'a R, ) -> Result<RoRange<'txn, KC, DC>>
where KC: BytesEncode<'a>, R: RangeBounds<KC::EItem>,

Return a lexicographically ordered iterator of a range of key-value pairs in this database.

Comparisons are made by using the bytes representation of the key.

You can make this iterator Sendable between threads by using the read-txn-no-tls crate feature.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI32, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?;

db.put(&mut wtxn, &42, "i-am-forty-two")?;
db.put(&mut wtxn, &27, "i-am-twenty-seven")?;
db.put(&mut wtxn, &13, "i-am-thirteen")?;
db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?;

let range = 27..=42;
let mut iter = db.range(&wtxn, &range)?;
assert_eq!(iter.next().transpose()?, Some((27, "i-am-twenty-seven")));
assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two")));
assert_eq!(iter.next().transpose()?, None);

drop(iter);
wtxn.commit()?;
source

pub fn range_mut<'a, 'txn, R>( &self, txn: &'txn mut RwTxn<'_>, range: &'a R, ) -> Result<RwRange<'txn, KC, DC>>
where KC: BytesEncode<'a>, R: RangeBounds<KC::EItem>,

Return a mutable lexicographically ordered iterator of a range of key-value pairs in this database.

Comparisons are made by using the bytes representation of the key.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI32, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?;

db.put(&mut wtxn, &42, "i-am-forty-two")?;
db.put(&mut wtxn, &27, "i-am-twenty-seven")?;
db.put(&mut wtxn, &13, "i-am-thirteen")?;
db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?;

let range = 27..=42;
let mut range = db.range_mut(&mut wtxn, &range)?;
assert_eq!(range.next().transpose()?, Some((27, "i-am-twenty-seven")));
let ret = unsafe { range.del_current()? };
assert!(ret);
assert_eq!(range.next().transpose()?, Some((42, "i-am-forty-two")));
let ret = unsafe { range.put_current(&42, "i-am-the-new-forty-two")? };
assert!(ret);

assert_eq!(range.next().transpose()?, None);
drop(range);


let mut iter = db.iter(&wtxn)?;
assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen")));
assert_eq!(iter.next().transpose()?, Some((42, "i-am-the-new-forty-two")));
assert_eq!(iter.next().transpose()?, Some((521, "i-am-five-hundred-and-twenty-one")));
assert_eq!(iter.next().transpose()?, None);

drop(iter);
wtxn.commit()?;
source

pub fn rev_range<'a, 'txn, R>( &self, txn: &'txn RoTxn<'_>, range: &'a R, ) -> Result<RoRevRange<'txn, KC, DC>>
where KC: BytesEncode<'a>, R: RangeBounds<KC::EItem>,

Return a reversed lexicographically ordered iterator of a range of key-value pairs in this database.

Comparisons are made by using the bytes representation of the key.

You can make this iterator Sendable between threads by using the read-txn-no-tls crate feature.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI32, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?;

db.put(&mut wtxn, &42, "i-am-forty-two")?;
db.put(&mut wtxn, &27, "i-am-twenty-seven")?;
db.put(&mut wtxn, &13, "i-am-thirteen")?;
db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?;

let range = 27..=43;
let mut iter = db.rev_range(&wtxn, &range)?;
assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two")));
assert_eq!(iter.next().transpose()?, Some((27, "i-am-twenty-seven")));
assert_eq!(iter.next().transpose()?, None);

drop(iter);
wtxn.commit()?;
source

pub fn rev_range_mut<'a, 'txn, R>( &self, txn: &'txn mut RwTxn<'_>, range: &'a R, ) -> Result<RwRevRange<'txn, KC, DC>>
where KC: BytesEncode<'a>, R: RangeBounds<KC::EItem>,

Return a mutable reversed lexicographically ordered iterator of a range of key-value pairs in this database.

Comparisons are made by using the bytes representation of the key.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI32, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?;

db.put(&mut wtxn, &42, "i-am-forty-two")?;
db.put(&mut wtxn, &27, "i-am-twenty-seven")?;
db.put(&mut wtxn, &13, "i-am-thirteen")?;
db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?;

let range = 27..=42;
let mut range = db.rev_range_mut(&mut wtxn, &range)?;
assert_eq!(range.next().transpose()?, Some((42, "i-am-forty-two")));
let ret = unsafe { range.del_current()? };
assert!(ret);
assert_eq!(range.next().transpose()?, Some((27, "i-am-twenty-seven")));
let ret = unsafe { range.put_current(&27, "i-am-the-new-twenty-seven")? };
assert!(ret);

assert_eq!(range.next().transpose()?, None);
drop(range);


let mut iter = db.iter(&wtxn)?;
assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen")));
assert_eq!(iter.next().transpose()?, Some((27, "i-am-the-new-twenty-seven")));
assert_eq!(iter.next().transpose()?, Some((521, "i-am-five-hundred-and-twenty-one")));
assert_eq!(iter.next().transpose()?, None);

drop(iter);
wtxn.commit()?;
source

pub fn prefix_iter<'a, 'txn>( &self, txn: &'txn RoTxn<'_>, prefix: &'a KC::EItem, ) -> Result<RoPrefix<'txn, KC, DC, C>>

Return a lexicographically ordered iterator of all key-value pairs in this database that starts with the given prefix.

Comparisons are made by using the bytes representation of the key.

You can make this iterator Sendable between threads by using the read-txn-no-tls crate feature.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<Str, BEI32> = env.create_database(&mut wtxn, Some("iter-i32"))?;

db.put(&mut wtxn, "i-am-twenty-eight", &28)?;
db.put(&mut wtxn, "i-am-twenty-seven", &27)?;
db.put(&mut wtxn, "i-am-twenty-nine",  &29)?;
db.put(&mut wtxn, "i-am-forty-one",    &41)?;
db.put(&mut wtxn, "i-am-forty-two",    &42)?;

let mut iter = db.prefix_iter(&mut wtxn, "i-am-twenty")?;
assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", 28)));
assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", 29)));
assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", 27)));
assert_eq!(iter.next().transpose()?, None);

drop(iter);
wtxn.commit()?;
source

pub fn prefix_iter_mut<'a, 'txn>( &self, txn: &'txn mut RwTxn<'_>, prefix: &'a KC::EItem, ) -> Result<RwPrefix<'txn, KC, DC, C>>

Return a mutable lexicographically ordered iterator of all key-value pairs in this database that starts with the given prefix.

Comparisons are made by using the bytes representation of the key.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<Str, BEI32> = env.create_database(&mut wtxn, Some("iter-i32"))?;

db.put(&mut wtxn, "i-am-twenty-eight", &28)?;
db.put(&mut wtxn, "i-am-twenty-seven", &27)?;
db.put(&mut wtxn, "i-am-twenty-nine",  &29)?;
db.put(&mut wtxn, "i-am-forty-one",    &41)?;
db.put(&mut wtxn, "i-am-forty-two",    &42)?;

let mut iter = db.prefix_iter_mut(&mut wtxn, "i-am-twenty")?;
assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", 28)));
let ret = unsafe { iter.del_current()? };
assert!(ret);

assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", 29)));
assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", 27)));
let ret = unsafe { iter.put_current("i-am-twenty-seven", &27000)? };
assert!(ret);

assert_eq!(iter.next().transpose()?, None);

drop(iter);

let ret = db.get(&wtxn, "i-am-twenty-eight")?;
assert_eq!(ret, None);

let ret = db.get(&wtxn, "i-am-twenty-seven")?;
assert_eq!(ret, Some(27000));

wtxn.commit()?;
source

pub fn rev_prefix_iter<'a, 'txn>( &self, txn: &'txn RoTxn<'_>, prefix: &'a KC::EItem, ) -> Result<RoRevPrefix<'txn, KC, DC, C>>

Return a reversed lexicographically ordered iterator of all key-value pairs in this database that starts with the given prefix.

Comparisons are made by using the bytes representation of the key.

You can make this iterator Sendable between threads by using the read-txn-no-tls crate feature.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<Str, BEI32> = env.create_database(&mut wtxn, Some("iter-i32"))?;

db.put(&mut wtxn, "i-am-twenty-eight", &28)?;
db.put(&mut wtxn, "i-am-twenty-seven", &27)?;
db.put(&mut wtxn, "i-am-twenty-nine",  &29)?;
db.put(&mut wtxn, "i-am-forty-one",    &41)?;
db.put(&mut wtxn, "i-am-forty-two",    &42)?;

let mut iter = db.rev_prefix_iter(&mut wtxn, "i-am-twenty")?;
assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", 27)));
assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", 29)));
assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", 28)));
assert_eq!(iter.next().transpose()?, None);

drop(iter);
wtxn.commit()?;
source

pub fn rev_prefix_iter_mut<'a, 'txn>( &self, txn: &'txn mut RwTxn<'_>, prefix: &'a KC::EItem, ) -> Result<RwRevPrefix<'txn, KC, DC, C>>

Return a mutable reversed lexicographically ordered iterator of all key-value pairs in this database that starts with the given prefix.

Comparisons are made by using the bytes representation of the key.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<Str, BEI32> = env.create_database(&mut wtxn, Some("iter-i32"))?;

db.put(&mut wtxn, "i-am-twenty-eight", &28)?;
db.put(&mut wtxn, "i-am-twenty-seven", &27)?;
db.put(&mut wtxn, "i-am-twenty-nine",  &29)?;
db.put(&mut wtxn, "i-am-forty-one",    &41)?;
db.put(&mut wtxn, "i-am-forty-two",    &42)?;

let mut iter = db.rev_prefix_iter_mut(&mut wtxn, "i-am-twenty")?;
assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-seven", 27)));
let ret = unsafe { iter.del_current()? };
assert!(ret);

assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-nine", 29)));
assert_eq!(iter.next().transpose()?, Some(("i-am-twenty-eight", 28)));
let ret = unsafe { iter.put_current("i-am-twenty-eight", &28000)? };
assert!(ret);

assert_eq!(iter.next().transpose()?, None);

drop(iter);

let ret = db.get(&wtxn, "i-am-twenty-seven")?;
assert_eq!(ret, None);

let ret = db.get(&wtxn, "i-am-twenty-eight")?;
assert_eq!(ret, Some(28000));

wtxn.commit()?;
source

pub fn put<'a>( &self, txn: &mut RwTxn<'_>, key: &'a KC::EItem, data: &'a DC::EItem, ) -> Result<()>
where KC: BytesEncode<'a>, DC: BytesEncode<'a>,

Insert a key-value pair in this database, replacing any previous value. The entry is written with no specific flag.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI32, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?;

db.put(&mut wtxn, &42, "i-am-forty-two")?;
db.put(&mut wtxn, &27, "i-am-twenty-seven")?;
db.put(&mut wtxn, &13, "i-am-thirteen")?;
db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?;

let ret = db.get(&mut wtxn, &27)?;
assert_eq!(ret, Some("i-am-twenty-seven"));

wtxn.commit()?;
source

pub fn put_reserved<'a, F>( &self, txn: &mut RwTxn<'_>, key: &'a KC::EItem, data_size: usize, write_func: F, ) -> Result<()>
where KC: BytesEncode<'a>, F: FnOnce(&mut ReservedSpace<'_>) -> Result<()>,

Insert a key-value pair where the value can directly be written to disk, replacing any previous value.

use std::io::Write;
use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db = env.create_database::<BEI32, Str>(&mut wtxn, Some("number-string"))?;

let value = "I am a long long long value";
db.put_reserved(&mut wtxn, &42, value.len(), |reserved| {
    reserved.write_all(value.as_bytes())
})?;

let ret = db.get(&mut wtxn, &42)?;
assert_eq!(ret, Some(value));

wtxn.commit()?;
source

pub fn put_with_flags<'a>( &self, txn: &mut RwTxn<'_>, flags: PutFlags, key: &'a KC::EItem, data: &'a DC::EItem, ) -> Result<()>
where KC: BytesEncode<'a>, DC: BytesEncode<'a>,

Insert a key-value pair in this database, replacing any previous value. The entry is written with the specified flags.

use heed::{Database, PutFlags, DatabaseFlags, Error, MdbError};
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db = env.database_options()
    .types::<BEI32, Str>()
    .name("dup-i32")
    .flags(DatabaseFlags::DUP_SORT)
    .create(&mut wtxn)?;

db.put(&mut wtxn, &42, "i-am-forty-two")?;
db.put(&mut wtxn, &42, "i-am-so-cool")?;
db.put(&mut wtxn, &42, "i-am-the-king")?;
db.put(&mut wtxn, &42, "i-am-fun")?;
db.put_with_flags(&mut wtxn, PutFlags::APPEND, &54, "i-am-older-than-you")?;
db.put_with_flags(&mut wtxn, PutFlags::APPEND_DUP, &54, "ok-but-i-am-better-than-you")?;
// You can compose flags by OR'ing them
db.put_with_flags(&mut wtxn, PutFlags::APPEND_DUP | PutFlags::NO_OVERWRITE, &55, "welcome")?;

// The NO_DUP_DATA flag will return KeyExist if we try to insert the exact same key/value pair.
let ret = db.put_with_flags(&mut wtxn, PutFlags::NO_DUP_DATA, &54, "ok-but-i-am-better-than-you");
assert!(matches!(ret, Err(Error::Mdb(MdbError::KeyExist))));

// The NO_OVERWRITE flag will return KeyExist if we try to insert something with an already existing key.
let ret = db.put_with_flags(&mut wtxn, PutFlags::NO_OVERWRITE, &54, "there-can-be-only-one-data");
assert!(matches!(ret, Err(Error::Mdb(MdbError::KeyExist))));

let mut iter = db.iter(&wtxn)?;
assert_eq!(iter.next().transpose()?, Some((42, "i-am-forty-two")));
assert_eq!(iter.next().transpose()?, Some((42, "i-am-fun")));
assert_eq!(iter.next().transpose()?, Some((42, "i-am-so-cool")));
assert_eq!(iter.next().transpose()?, Some((42, "i-am-the-king")));
assert_eq!(iter.next().transpose()?, Some((54, "i-am-older-than-you")));
assert_eq!(iter.next().transpose()?, Some((54, "ok-but-i-am-better-than-you")));
assert_eq!(iter.next().transpose()?, Some((55, "welcome")));
assert_eq!(iter.next().transpose()?, None);

drop(iter);
wtxn.commit()?;
source

pub fn get_or_put<'a, 'txn>( &'txn self, txn: &mut RwTxn<'_>, key: &'a KC::EItem, data: &'a DC::EItem, ) -> Result<Option<DC::DItem>>
where KC: BytesEncode<'a>, DC: BytesEncode<'a> + BytesDecode<'a>,

Attempt to insert a key-value pair in this database, or if a value already exists for the key, returns the previous value.

The entry is always written with the NO_OVERWRITE flag.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI32, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?;

assert_eq!(db.get_or_put(&mut wtxn, &42, "i-am-forty-two")?, None);
assert_eq!(db.get_or_put(&mut wtxn, &42, "the meaning of life")?, Some("i-am-forty-two"));

let ret = db.get(&mut wtxn, &42)?;
assert_eq!(ret, Some("i-am-forty-two"));

wtxn.commit()?;
source

pub fn get_or_put_with_flags<'a, 'txn>( &'txn self, txn: &mut RwTxn<'_>, flags: PutFlags, key: &'a KC::EItem, data: &'a DC::EItem, ) -> Result<Option<DC::DItem>>
where KC: BytesEncode<'a>, DC: BytesEncode<'a> + BytesDecode<'a>,

Attempt to insert a key-value pair in this database, or if a value already exists for the key, returns the previous value.

The entry is written with the specified flags, in addition to NO_OVERWRITE which is always used.

use heed::{Database, PutFlags};
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI32, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?;

assert_eq!(db.get_or_put_with_flags(&mut wtxn, PutFlags::empty(), &42, "i-am-forty-two")?, None);
assert_eq!(db.get_or_put_with_flags(&mut wtxn, PutFlags::empty(), &42, "the meaning of life")?, Some("i-am-forty-two"));

let ret = db.get(&mut wtxn, &42)?;
assert_eq!(ret, Some("i-am-forty-two"));

wtxn.commit()?;
source

pub fn get_or_put_reserved<'a, 'txn, F>( &'txn self, txn: &mut RwTxn<'_>, key: &'a KC::EItem, data_size: usize, write_func: F, ) -> Result<Option<DC::DItem>>
where KC: BytesEncode<'a>, F: FnOnce(&mut ReservedSpace<'_>) -> Result<()>, DC: BytesDecode<'a>,

Attempt to insert a key-value pair in this database, where the value can be directly written to disk, or if a value already exists for the key, returns the previous value.

The entry is always written with the NO_OVERWRITE and MDB_RESERVE flags.

use std::io::Write;
use heed::{Database, PutFlags};
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db = env.create_database::<BEI32, Str>(&mut wtxn, Some("number-string"))?;

let long = "I am a long long long value";
assert_eq!(
    db.get_or_put_reserved(&mut wtxn, &42, long.len(), |reserved| {
        reserved.write_all(long.as_bytes())
    })?,
    None
);

let longer = "I am an even longer long long long value";
assert_eq!(
    db.get_or_put_reserved(&mut wtxn, &42, longer.len(), |reserved| {
        unreachable!()
    })?,
    Some(long)
);

let ret = db.get(&mut wtxn, &42)?;
assert_eq!(ret, Some(long));

wtxn.commit()?;
source

pub fn get_or_put_reserved_with_flags<'a, 'txn, F>( &'txn self, txn: &mut RwTxn<'_>, flags: PutFlags, key: &'a KC::EItem, data_size: usize, write_func: F, ) -> Result<Option<DC::DItem>>
where KC: BytesEncode<'a>, F: FnOnce(&mut ReservedSpace<'_>) -> Result<()>, DC: BytesDecode<'a>,

Attempt to insert a key-value pair in this database, where the value can be directly written to disk, or if a value already exists for the key, returns the previous value.

The entry is written with the specified flags, in addition to NO_OVERWRITE and MDB_RESERVE which are always used.

use std::io::Write;
use heed::{Database, PutFlags};
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db = env.create_database::<BEI32, Str>(&mut wtxn, Some("number-string"))?;

let long = "I am a long long long value";
assert_eq!(
    db.get_or_put_reserved_with_flags(&mut wtxn, PutFlags::empty(), &42, long.len(), |reserved| {
        reserved.write_all(long.as_bytes())
    })?,
    None
);

let longer = "I am an even longer long long long value";
assert_eq!(
    db.get_or_put_reserved_with_flags(&mut wtxn, PutFlags::empty(), &42, longer.len(), |reserved| {
        unreachable!()
    })?,
    Some(long)
);

let ret = db.get(&mut wtxn, &42)?;
assert_eq!(ret, Some(long));

wtxn.commit()?;
source

pub fn delete<'a>( &self, txn: &mut RwTxn<'_>, key: &'a KC::EItem, ) -> Result<bool>
where KC: BytesEncode<'a>,

Deletes an entry or every duplicate data items of a key if the database supports duplicate data items.

If the entry does not exist, then false is returned.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI32, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?;

db.put(&mut wtxn, &42, "i-am-forty-two")?;
db.put(&mut wtxn, &27, "i-am-twenty-seven")?;
db.put(&mut wtxn, &13, "i-am-thirteen")?;
db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?;

let ret = db.delete(&mut wtxn, &27)?;
assert_eq!(ret, true);

let ret = db.get(&mut wtxn, &27)?;
assert_eq!(ret, None);

let ret = db.delete(&mut wtxn, &467)?;
assert_eq!(ret, false);

wtxn.commit()?;
source

pub fn delete_one_duplicate<'a>( &self, txn: &mut RwTxn<'_>, key: &'a KC::EItem, data: &'a DC::EItem, ) -> Result<bool>
where KC: BytesEncode<'a>, DC: BytesEncode<'a>,

Deletes a single key-value pair in this database.

If the database doesn’t support duplicate data items the data is ignored. If the key does not exist, then false is returned.

use heed::types::*;
use heed::byteorder::BigEndian;

type BEI64 = I64<BigEndian>;

let mut wtxn = env.write_txn()?;
let db = env.database_options()
    .types::<BEI64, BEI64>()
    .flags(DatabaseFlags::DUP_SORT)
    .name("dup-sort")
    .create(&mut wtxn)?;

db.put(&mut wtxn, &68, &120)?;
db.put(&mut wtxn, &68, &121)?;
db.put(&mut wtxn, &68, &122)?;
db.put(&mut wtxn, &68, &123)?;
db.put(&mut wtxn, &92, &32)?;
db.put(&mut wtxn, &35, &120)?;
db.put(&mut wtxn, &0, &120)?;
db.put(&mut wtxn, &42, &120)?;

let mut iter = db.get_duplicates(&wtxn, &68)?.expect("the key exists");
assert_eq!(iter.next().transpose()?, Some((68, 120)));
assert_eq!(iter.next().transpose()?, Some((68, 121)));
assert_eq!(iter.next().transpose()?, Some((68, 122)));
assert_eq!(iter.next().transpose()?, Some((68, 123)));
assert_eq!(iter.next().transpose()?, None);
drop(iter);

assert!(db.delete_one_duplicate(&mut wtxn, &68, &121)?, "The entry must exist");

let mut iter = db.get_duplicates(&wtxn, &68)?.expect("the key exists");
assert_eq!(iter.next().transpose()?, Some((68, 120)));
// No more (68, 121) returned here!
assert_eq!(iter.next().transpose()?, Some((68, 122)));
assert_eq!(iter.next().transpose()?, Some((68, 123)));
assert_eq!(iter.next().transpose()?, None);
drop(iter);

wtxn.commit()?;
source

pub fn delete_range<'a, 'txn, R>( &self, txn: &'txn mut RwTxn<'_>, range: &'a R, ) -> Result<usize>
where KC: BytesEncode<'a> + BytesDecode<'txn>, R: RangeBounds<KC::EItem>,

Deletes a range of key-value pairs in this database.

Prefer using clear instead of a call to this method with a full range (..).

Comparisons are made by using the bytes representation of the key.

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI32, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?;

db.put(&mut wtxn, &42, "i-am-forty-two")?;
db.put(&mut wtxn, &27, "i-am-twenty-seven")?;
db.put(&mut wtxn, &13, "i-am-thirteen")?;
db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?;

let range = 27..=42;
let ret = db.delete_range(&mut wtxn, &range)?;
assert_eq!(ret, 2);


let mut iter = db.iter(&wtxn)?;
assert_eq!(iter.next().transpose()?, Some((13, "i-am-thirteen")));
assert_eq!(iter.next().transpose()?, Some((521, "i-am-five-hundred-and-twenty-one")));
assert_eq!(iter.next().transpose()?, None);

drop(iter);
wtxn.commit()?;
source

pub fn clear(&self, txn: &mut RwTxn<'_>) -> Result<()>

Deletes all key/value pairs in this database.

Prefer using this method instead of a call to delete_range with a full range (..).

use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<BEI32, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?;

db.put(&mut wtxn, &42, "i-am-forty-two")?;
db.put(&mut wtxn, &27, "i-am-twenty-seven")?;
db.put(&mut wtxn, &13, "i-am-thirteen")?;
db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?;

db.clear(&mut wtxn)?;

let ret = db.is_empty(&wtxn)?;
assert!(ret);

wtxn.commit()?;
source

pub fn remap_types<KC2, DC2>(&self) -> Database<KC2, DC2, C>

Change the codec types of this database, specifying the codecs.

§Safety

It is up to you to ensure that the data read and written using the polymorphic handle correspond to the the typed, uniform one. If an invalid write is made, it can corrupt the database from the eyes of heed.

§Example
use heed::Database;
use heed::types::*;
use heed::byteorder::BigEndian;

type BEI32 = I32<BigEndian>;

let mut wtxn = env.write_txn()?;
let db: Database<Unit, Unit> = env.create_database(&mut wtxn, Some("iter-i32"))?;

// We remap the types for ease of use.
let db = db.remap_types::<BEI32, Str>();
db.put(&mut wtxn, &42, "i-am-forty-two")?;
db.put(&mut wtxn, &27, "i-am-twenty-seven")?;
db.put(&mut wtxn, &13, "i-am-thirteen")?;
db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?;

wtxn.commit()?;
source

pub fn remap_key_type<KC2>(&self) -> Database<KC2, DC, C>

Change the key codec type of this database, specifying the new codec.

source

pub fn remap_data_type<DC2>(&self) -> Database<KC, DC2, C>

Change the data codec type of this database, specifying the new codec.

source

pub fn lazily_decode_data(&self) -> Database<KC, LazyDecode<DC>, C>

Wrap the data bytes into a lazy decoder.

Trait Implementations§

source§

impl<KC, DC, C> Clone for Database<KC, DC, C>

source§

fn clone(&self) -> Database<KC, DC, C>

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<KC, DC, C> Debug for Database<KC, DC, C>

source§

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

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

impl<KC, DC, C> Copy for Database<KC, DC, C>

Auto Trait Implementations§

§

impl<KC, DC, C> Freeze for Database<KC, DC, C>

§

impl<KC, DC, C> RefUnwindSafe for Database<KC, DC, C>

§

impl<KC, DC, C> Send for Database<KC, DC, C>
where KC: Send, DC: Send, C: Send,

§

impl<KC, DC, C> Sync for Database<KC, DC, C>
where KC: Sync, DC: Sync, C: Sync,

§

impl<KC, DC, C> Unpin for Database<KC, DC, C>
where KC: Unpin, DC: Unpin, C: Unpin,

§

impl<KC, DC, C> UnwindSafe for Database<KC, DC, C>
where KC: UnwindSafe, DC: UnwindSafe, C: UnwindSafe,

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> 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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 16 bytes