Use the byte-unit crate to ease library usage

This commit is contained in:
Kerollmops 2020-12-20 11:55:21 +01:00
parent b032ceb5d4
commit 77e951e933
No known key found for this signature in database
GPG key ID: 92ADA4E935E71FA4
7 changed files with 57 additions and 19 deletions

View file

@ -2,9 +2,10 @@ use std::path::PathBuf;
use std::{str, io, fmt};
use anyhow::Context;
use byte_unit::Byte;
use crate::Index;
use heed::EnvOpenOptions;
use structopt::StructOpt;
use crate::Index;
use Command::*;
@ -39,8 +40,8 @@ pub struct Opt {
/// The maximum size the database can take on disk. It is recommended to specify
/// the whole disk space (value must be a multiple of a page size).
#[structopt(long = "db-size", default_value = "107374182400")] // 100 GB
database_size: usize,
#[structopt(long = "db-size", default_value = "100 GiB")]
database_size: Byte,
/// Verbose mode (-v, -vv, -vvv, etc.)
#[structopt(short, long, parse(from_occurrences))]
@ -159,7 +160,7 @@ pub fn run(opt: Opt) -> anyhow::Result<()> {
.init()?;
let mut options = EnvOpenOptions::new();
options.map_size(opt.database_size);
options.map_size(opt.database_size.get_bytes() as usize);
// Open the LMDB database.
let index = Index::new(options, opt.database)?;

View file

@ -5,6 +5,7 @@ use std::path::PathBuf;
use std::time::Instant;
use anyhow::Context;
use byte_unit::Byte;
use heed::EnvOpenOptions;
use log::debug;
use structopt::StructOpt;
@ -21,8 +22,8 @@ pub struct Opt {
/// The maximum size the database can take on disk. It is recommended to specify
/// the whole disk space (value must be a multiple of a page size).
#[structopt(long = "db-size", default_value = "107374182400")] // 100 GB
database_size: usize,
#[structopt(long = "db-size", default_value = "100 GiB")]
database_size: Byte,
/// Verbose mode (-v, -vv, -vvv, etc.)
#[structopt(short, long, parse(from_occurrences))]
@ -41,7 +42,7 @@ pub fn run(opt: Opt) -> anyhow::Result<()> {
std::fs::create_dir_all(&opt.database)?;
let mut options = EnvOpenOptions::new();
options.map_size(opt.database_size);
options.map_size(opt.database_size.get_bytes() as usize);
// Open the LMDB database.
let index = Index::new(options, &opt.database)?;