Skip to content

Commit

Permalink
docs(cursors): Add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Alorel committed Aug 17, 2021
1 parent 46009d0 commit 2607e7c
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/idb_cursor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
//! Cursor-related code
//!
//! Features required: `cursors`
//!
//! ## Examples
//!
// use super::{*, prelude::*};
// use wasm_bindgen::prelude::*;
// use web_sys::DomException;
//
// #[allow(unused_variables)]
// async fn example() -> Result<(), DomException> {
// let db = IdbDatabase::open("foo_db")?.into_future().await?;
// let tx = db.transaction_on_one("foo_store")?;
// let object_store = tx.object_store("foo_store")?;
//
//! match object_store.open_cursor()?.await? {
//! Some(cursor) => {
//! let first_key: JsValue = cursor.key().unwrap();
//! let first_value: JsValue = cursor.value();
//!
//! // Iterate one by one
//! while cursor.continue_cursor()?.await? {
//! let subsequent_key: JsValue = cursor.key().unwrap();
//! let subsequent_value: JsValue = cursor.value();
//! }
//!
//! // Or collect the remainder into a vector
//! let cursor_contents: Vec<KeyVal> = cursor.into_vec(0).await?;
//! },
//! None => {
//! // No elements matched
//! }
//! };
//
// Ok(())
// }

use std::future::Future;
use std::rc::Rc;
Expand Down

0 comments on commit 2607e7c

Please sign in to comment.