Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Impressum iterator.rs

  Sprache: Rust
 

// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

//! A demo that showcases the basic usage of iterators in rkv.
//!
//! You can test this out by running:
//!
//!     cargo run --example iterator

use std::{fs, str};

use tempfile::Builder;

use rkv::{
    backend::{SafeMode, SafeModeDatabase, SafeModeEnvironment},
    Manager, Rkv, SingleStore, StoreError, StoreOptions, Value,
};

fn main() {
    let root = Builder::new().prefix("iterator").tempdir().unwrap();
    fs::create_dir_all(root.path()).unwrap();
    let p = root.path();

    let mut manager = Manager::<SafeModeEnvironment>::singleton().write().unwrap();
    let created_arc = manager.get_or_create(p, Rkv::new::<SafeMode>).unwrap();
    let k = created_arc.read().unwrap();
    let store = k.open_single("store", StoreOptions::create()).unwrap();

    populate_store(&k, store).unwrap();

    let reader = k.read().unwrap();

    println!("Iterating from the beginning...");
    // Reader::iter_start() iterates from the first item in the store, and
    // returns the (key, value) tuples in order.
    let mut iter = store.iter_start(&reader).unwrap();
    while let Some(Ok((country, city))) = iter.next() {
        let country = str::from_utf8(country).unwrap();
        println!("{country}, {city:?}");
    }

    println!();
    println!("Iterating from the given key...");
    // Reader::iter_from() iterates from the first key equal to or greater
    // than the given key.
    let mut iter = store.iter_from(&reader, "Japan").unwrap();
    while let Some(Ok((country, city))) = iter.next() {
        println!("{}, {city:?}", str::from_utf8(country).unwrap());
    }

    println!();
    println!("Iterating from the given prefix...");
    let mut iter = store.iter_from(&reader, "Un").unwrap();
    while let Some(Ok((country, city))) = iter.next() {
        println!("{}, {city:?}", str::from_utf8(country).unwrap());
    }
}

fn populate_store(
    k: &Rkv<SafeModeEnvironment>,
    store: SingleStore<SafeModeDatabase>,
) -> Result<(), StoreError> {
    let mut writer = k.write()?;
    for (country, city) in vec![
        ("Canada", Value::Str("Ottawa")),
        ("United States of America", Value::Str("Washington")),
        ("Germany", Value::Str("Berlin")),
        ("France", Value::Str("Paris")),
        ("Italy", Value::Str("Rome")),
        ("United Kingdom", Value::Str("London")),
        ("Japan", Value::Str("Tokyo")),
    ] {
        store.put(&mut writer, country, &city)?;
    }
    writer.commit()
}

Messung V0.5 in Prozent
C=81 H=95 G=88

¤ Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.0.18Bemerkung:  (vorverarbeitet am  2026-06-19) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik