|
|
@ -660,28 +660,37 @@ impl DB { |
|
|
|
|
|
|
|
|
|
|
|
/// Open the database with the specified options.
|
|
|
|
/// Open the database with the specified options.
|
|
|
|
pub fn open<P: AsRef<Path>>(opts: &Options, path: P) -> Result<DB, Error> { |
|
|
|
pub fn open<P: AsRef<Path>>(opts: &Options, path: P) -> Result<DB, Error> { |
|
|
|
DB::open_cf(opts, path, &[]) |
|
|
|
DB::open_cf(opts, path, None::<&str>) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Open a database with the given database options and column family names.
|
|
|
|
/// Open a database with the given database options and column family names.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// Column families opened using this function will be created with default `Options`.
|
|
|
|
/// Column families opened using this function will be created with default `Options`.
|
|
|
|
pub fn open_cf<P: AsRef<Path>>(opts: &Options, path: P, cfs: &[&str]) -> Result<DB, Error> { |
|
|
|
pub fn open_cf<P, I, N>(opts: &Options, path: P, cfs: I) -> Result<DB, Error>
|
|
|
|
let cfs_v = cfs |
|
|
|
where P: AsRef<Path>, |
|
|
|
.to_vec() |
|
|
|
I: IntoIterator<Item = N>, |
|
|
|
.iter() |
|
|
|
N: AsRef<str> { |
|
|
|
.map(|name| ColumnFamilyDescriptor::new(*name, Options::default())) |
|
|
|
|
|
|
|
.collect(); |
|
|
|
let cfs = cfs |
|
|
|
|
|
|
|
.into_iter() |
|
|
|
|
|
|
|
.map(|name| ColumnFamilyDescriptor::new(name.as_ref(), Options::default())); |
|
|
|
|
|
|
|
|
|
|
|
DB::open_cf_descriptors(opts, path, cfs_v) |
|
|
|
DB::open_cf_descriptors(opts, path, cfs) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Open a database with the given database options and column family names/options.
|
|
|
|
/// Open a database with the given database options and column family descriptors.
|
|
|
|
pub fn open_cf_descriptors<P: AsRef<Path>>( |
|
|
|
pub fn open_cf_descriptors<P, I>( |
|
|
|
opts: &Options, |
|
|
|
opts: &Options, |
|
|
|
path: P, |
|
|
|
path: P, |
|
|
|
cfs: Vec<ColumnFamilyDescriptor>, |
|
|
|
cfs: I, |
|
|
|
) -> Result<DB, Error> { |
|
|
|
) -> Result<DB, Error>
|
|
|
|
|
|
|
|
where P: AsRef<Path>, |
|
|
|
|
|
|
|
I: IntoIterator<Item = ColumnFamilyDescriptor> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let cfs: Vec<_> = cfs |
|
|
|
|
|
|
|
.into_iter() |
|
|
|
|
|
|
|
.collect(); |
|
|
|
|
|
|
|
|
|
|
|
let path = path.as_ref(); |
|
|
|
let path = path.as_ref(); |
|
|
|
let cpath = match CString::new(path.to_string_lossy().as_bytes()) { |
|
|
|
let cpath = match CString::new(path.to_string_lossy().as_bytes()) { |
|
|
|
Ok(c) => c, |
|
|
|
Ok(c) => c, |
|
|
|