Function db_dump::load_all

source ·
pub fn load_all(path: impl AsRef<Path>) -> Result<DbDump>
Expand description

Deserialize everything in a crates.io DB dump into memory.

This function is equivalent to the following Loader-based invocation:

let mut categories = Vec::new();
let mut crate_owners = Vec::new();
/* ... */
let mut versions = Vec::new();

db_dump::Loader::new()
    .categories(|row| categories.push(row))
    .crate_owners(|row| crate_owners.push(row))
    /* ... */
    .versions(|row| versions.push(row))
    .load(path)?;

Ok(DbDump {
    categories,
    crate_owners,
    /* ... */
    versions,
})

Usually whatever you are doing will not require all of the information in a dump, in which case utilizing Loader to load just what you need can be significantly more efficient.

Examples found in repository?
examples/load-all.rs (line 10)
7
8
9
10
11
12
13
14
15
16
fn main() -> db_dump::Result<()> {
    let start = Instant::now();

    let db = db_dump::load_all("./db-dump.tar.gz")?;

    let elapsed = start.elapsed();
    println!("{}.{:03}sec", elapsed.as_secs(), elapsed.subsec_millis());
    drop(db);
    Ok(())
}