Skip to content

Commit 263d504

Browse files
committed
simpler example.
1 parent 23b8f71 commit 263d504

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

heed/src/cookbook.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,10 @@
585585
//!
586586
//! When working with databases that have sorted keys, you might want to iterate over a specific range
587587
//! of keys starting from a particular key. Heed provides the [`Database::range`] method that accepts
588-
//! any type implementing [`RangeBounds`].
588+
//! any type implementing [`std::ops::RangeBounds`].
589589
//!
590-
//! Specifically, if your keys are of type [`Bytes`] and you have a `Vec<u8>` as your starting key
591-
//! you can use that in in a [`Database::range`] call like this:
590+
//! Specifically, if your keys are of type [`heed::types::Bytes`] and you have a `Vec<u8>` as your starting key,
591+
//! because a tuple of [`std::ops::Bound`] implements such trait you can just use that:
592592
//!
593593
//! ```
594594
//! use std::error::Error;
@@ -599,25 +599,13 @@
599599
//! use heed::types::*;
600600
//! use heed::{Database, DatabaseFlags, EnvOpenOptions};
601601
//!
602-
//! struct BytesRange(Vec<u8>);
603-
//!
604-
//! impl std::ops::RangeBounds<[u8]> for BytesRange {
605-
//! fn start_bound(&self) -> std::ops::Bound<&[u8]> {
606-
//! std::ops::Bound::Included(&self.0)
607-
//! }
608-
//!
609-
//! fn end_bound(&self) -> std::ops::Bound<&[u8]> {
610-
//! std::ops::Bound::Unbounded
611-
//! }
612-
//! }
613-
//!
614602
//! fn main() -> Result<(), Box<dyn Error>> {
615603
//! let path = tempfile::tempdir()?;
616604
//!
617605
//! let env = unsafe {
618606
//! EnvOpenOptions::new()
619607
//! .map_size(1 << 34)
620-
//! .max_dbs(8)
608+
//! .max_dbs(1)
621609
//! .open(&path)?
622610
//! };
623611
//!
@@ -627,7 +615,6 @@
627615
//! .database_options()
628616
//! .types::<Bytes, U64<NativeEndian>>()
629617
//! .name("index")
630-
//! .flags(DatabaseFlags::DUP_SORT | DatabaseFlags::DUP_FIXED)
631618
//! .create(&mut wtxn)?;
632619
//!
633620
//! db.put(&mut wtxn, &vec![1, 2, 3, 3], &55555u64)?;
@@ -639,7 +626,14 @@
639626
//! let txn = env.read_txn()?;
640627
//! let key: Vec<u8> = vec![1, 2, 3, 4];
641628
//!
642-
//! for result in db.range(&txn, &BytesRange(key))? {
629+
//! for res in db
630+
//! .range(
631+
//! &txn,
632+
//! &(
633+
//! std::ops::Bound::Included(key.as_slice()),
634+
//! std::ops::Bound::Unbounded,
635+
//! ),
636+
//! )? {
643637
//! let (k, v) = result?;
644638
//! println!("Key: {:?}, Value: {}", k, v);
645639
//! }

0 commit comments

Comments
 (0)