pub struct Config(/* private fields */);
Expand description
Top-level configuration for the system.
§Examples
let _config = sled::Config::default()
.path("/path/to/data".to_owned())
.cache_capacity(10_000_000_000)
.flush_every_ms(Some(1000));
Implementations§
Source§impl Config
impl Config
Sourcepub fn new() -> Config
pub fn new() -> Config
Returns a default Config
Examples found in repository?
examples/basic.rs (line 6)
3 4 5 6 7 8 9 10 11 12 13 14 15
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Creating a temporary sled database.
// If you want to persist the data use sled::open instead.
let db = sled::Config::new().temporary(true).open().unwrap();
// The id is used by sled to identify which Tree in the database (db) to open
let tree = bincode_sled::Tree::<String, SomeValue>::open(&db, "unique_id");
tree.insert(&"some_key".to_owned(), &SomeValue(10))?;
assert_eq!(tree.get(&"some_key".to_owned())?, Some(SomeValue(10)));
Ok(())
}
Sourcepub fn open(&self) -> Result<Db, Error>
pub fn open(&self) -> Result<Db, Error>
Opens a Db
based on the provided config.
Examples found in repository?
examples/basic.rs (line 6)
3 4 5 6 7 8 9 10 11 12 13 14 15
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Creating a temporary sled database.
// If you want to persist the data use sled::open instead.
let db = sled::Config::new().temporary(true).open().unwrap();
// The id is used by sled to identify which Tree in the database (db) to open
let tree = bincode_sled::Tree::<String, SomeValue>::open(&db, "unique_id");
tree.insert(&"some_key".to_owned(), &SomeValue(10))?;
assert_eq!(tree.get(&"some_key".to_owned())?, Some(SomeValue(10)));
Ok(())
}
Sourcepub fn cache_capacity(self, to: u64) -> Config
pub fn cache_capacity(self, to: u64) -> Config
maximum size in bytes for the system page cache
Sourcepub fn mode(self, to: Mode) -> Config
pub fn mode(self, to: Mode) -> Config
specify whether the system should run in “small” or “fast” mode
Sourcepub fn use_compression(self, to: bool) -> Config
pub fn use_compression(self, to: bool) -> Config
whether to use zstd compression
Sourcepub fn compression_factor(self, to: i32) -> Config
pub fn compression_factor(self, to: i32) -> Config
the compression factor to use with zstd compression. Ranges from 1 up to 22. Levels >= 20 are ‘ultra’.
Sourcepub fn temporary(self, to: bool) -> Config
pub fn temporary(self, to: bool) -> Config
deletes the database after drop. if no path is set, uses /dev/shm on linux
Examples found in repository?
examples/basic.rs (line 6)
3 4 5 6 7 8 9 10 11 12 13 14 15
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Creating a temporary sled database.
// If you want to persist the data use sled::open instead.
let db = sled::Config::new().temporary(true).open().unwrap();
// The id is used by sled to identify which Tree in the database (db) to open
let tree = bincode_sled::Tree::<String, SomeValue>::open(&db, "unique_id");
tree.insert(&"some_key".to_owned(), &SomeValue(10))?;
assert_eq!(tree.get(&"some_key".to_owned())?, Some(SomeValue(10)));
Ok(())
}
Sourcepub fn create_new(self, to: bool) -> Config
pub fn create_new(self, to: bool) -> Config
attempts to exclusively open the database, failing if it already exists
Sourcepub fn print_profile_on_drop(self, to: bool) -> Config
pub fn print_profile_on_drop(self, to: bool) -> Config
print a performance profile when the Config is dropped
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl !RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl !UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more