pub struct MMKV { /* private fields */ }
Implementations§
source§impl MMKV
impl MMKV
sourcepub fn new(dir: &str) -> Self
pub fn new(dir: &str) -> Self
Initialize the MMKV instance with a writeable directory, absolute or relative paths are acceptable.
All API calls(except set_logger, set_log_level) before initialization will panic.
Calling initialize multiple times is allowed, the old instance will be closed (see close), the last call will take over.
If enabled feature “encryption”, additional param key
is required,
the key should be a hexadecimal string of length 16, for example:
88C51C536176AD8A8EE4A06F62EE897E
pub fn put_str(&self, key: &str, value: &str) -> Result<()>
pub fn get_str(&self, key: &str) -> Result<String>
pub fn put_i32(&self, key: &str, value: i32) -> Result<()>
pub fn get_i32(&self, key: &str) -> Result<i32>
pub fn put_bool(&self, key: &str, value: bool) -> Result<()>
pub fn get_bool(&self, key: &str) -> Result<bool>
pub fn put_i64(&self, key: &str, value: i64) -> Result<()>
pub fn get_i64(&self, key: &str) -> Result<i64>
pub fn put_f32(&self, key: &str, value: f32) -> Result<()>
pub fn get_f32(&self, key: &str) -> Result<f32>
pub fn put_f64(&self, key: &str, value: f64) -> Result<()>
pub fn get_f64(&self, key: &str) -> Result<f64>
pub fn put_byte_array(&self, key: &str, value: &[u8]) -> Result<()>
pub fn get_byte_array(&self, key: &str) -> Result<Vec<u8>>
pub fn put_i32_array(&self, key: &str, value: &[i32]) -> Result<()>
pub fn get_i32_array(&self, key: &str) -> Result<Vec<i32>>
pub fn put_i64_array(&self, key: &str, value: &[i64]) -> Result<()>
pub fn get_i64_array(&self, key: &str) -> Result<Vec<i64>>
pub fn put_f32_array(&self, key: &str, value: &[f32]) -> Result<()>
pub fn get_f32_array(&self, key: &str) -> Result<Vec<f32>>
pub fn put_f64_array(&self, key: &str, value: &[f64]) -> Result<()>
pub fn get_f64_array(&self, key: &str) -> Result<Vec<f64>>
pub fn delete(&self, key: &str) -> Result<()>
sourcepub fn clear_data(&self)
pub fn clear_data(&self)
Clear all data.
sourcepub fn set_logger(log_impl: Box<dyn Logger>)
pub fn set_logger(log_impl: Box<dyn Logger>)
Set a custom logger for MMKV, MMKV will redirect the inner logs to this logger.
The default impl of Logger is like this:
use mmkv::Logger;
#[derive(Debug)]
struct DefaultLogger;
impl Logger for DefaultLogger {
fn verbose(&self, log_str: String) {
println!("{log_str}");
}
fn info(&self, log_str: String) {
println!("{log_str}");
}
fn debug(&self, log_str: String) {
println!("{log_str}");
}
fn warn(&self, log_str: String) {
println!("{log_str}");
}
fn error(&self, log_str: String) {
println!("{log_str}");
}
}
sourcepub fn set_log_level(level: LogLevel)
pub fn set_log_level(level: LogLevel)
Set log level to mmkv:
- LogLevel::Off, no log,
- LogLevel::Error: only display Error logs,
- LogLevel::Warn: display Error and Warn,
- LogLevel::Info: display Error, Warn and Info,
- LogLevel::Debug: display Error, Warn, Info and Debug,
- LogLevel::Verbose: display all logs.
The default log level is LogLevel::Verbose.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MMKV
impl RefUnwindSafe for MMKV
impl Send for MMKV
impl Sync for MMKV
impl Unpin for MMKV
impl UnwindSafe for MMKV
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