1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use std::path::Path;
use crate::open_raw::{OpenRaw, OpenRawInput};
use crate::{ColumnFamilyDescriptor, Error, Options};
pub trait Open: OpenRaw {
fn open_default<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
let mut opts = Options::default();
opts.create_if_missing(true);
Self::open(&opts, path)
}
fn open<P: AsRef<Path>>(opts: &Options, path: P) -> Result<Self, Error> {
Self::open_with_descriptor(opts, path, Self::Descriptor::default())
}
fn open_with_descriptor<P: AsRef<Path>>(
opts: &Options,
path: P,
descriptor: Self::Descriptor,
) -> Result<Self, Error> {
let input = OpenRawInput {
options: opts,
path: path.as_ref(),
column_families: vec![],
open_descriptor: descriptor,
};
Self::open_raw(input)
}
}
pub trait OpenCF: OpenRaw {
fn open_cf<P, I, N>(opts: &Options, path: P, cfs: I) -> Result<Self, Error>
where
P: AsRef<Path>,
I: IntoIterator<Item = N>,
N: AsRef<str>,
{
let cfs = cfs
.into_iter()
.map(|name| ColumnFamilyDescriptor::new(name.as_ref(), Options::default()));
Self::open_cf_descriptors(opts, path, cfs)
}
fn open_cf_descriptors<P, I>(opts: &Options, path: P, cfs: I) -> Result<Self, Error>
where
P: AsRef<Path>,
I: IntoIterator<Item = ColumnFamilyDescriptor>,
{
Self::open_cf_descriptors_with_descriptor(opts, path, cfs, Self::Descriptor::default())
}
fn open_cf_descriptors_with_descriptor<P, I>(
opts: &Options,
path: P,
cfs: I,
descriptor: Self::Descriptor,
) -> Result<Self, Error>
where
P: AsRef<Path>,
I: IntoIterator<Item = ColumnFamilyDescriptor>,
{
let input = OpenRawInput {
options: opts,
path: path.as_ref(),
column_families: cfs.into_iter().collect(),
open_descriptor: descriptor,
};
Self::open_raw(input)
}
}