Struct mmkv::MMKV

source ·
pub struct MMKV { /* private fields */ }

Implementations§

source§

impl MMKV

source

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

source

pub fn put_str(&self, key: &str, value: &str) -> Result<()>

source

pub fn get_str(&self, key: &str) -> Result<String>

source

pub fn put_i32(&self, key: &str, value: i32) -> Result<()>

source

pub fn get_i32(&self, key: &str) -> Result<i32>

source

pub fn put_bool(&self, key: &str, value: bool) -> Result<()>

source

pub fn get_bool(&self, key: &str) -> Result<bool>

source

pub fn put_i64(&self, key: &str, value: i64) -> Result<()>

source

pub fn get_i64(&self, key: &str) -> Result<i64>

source

pub fn put_f32(&self, key: &str, value: f32) -> Result<()>

source

pub fn get_f32(&self, key: &str) -> Result<f32>

source

pub fn put_f64(&self, key: &str, value: f64) -> Result<()>

source

pub fn get_f64(&self, key: &str) -> Result<f64>

source

pub fn put_byte_array(&self, key: &str, value: &[u8]) -> Result<()>

source

pub fn get_byte_array(&self, key: &str) -> Result<Vec<u8>>

source

pub fn put_i32_array(&self, key: &str, value: &[i32]) -> Result<()>

source

pub fn get_i32_array(&self, key: &str) -> Result<Vec<i32>>

source

pub fn put_i64_array(&self, key: &str, value: &[i64]) -> Result<()>

source

pub fn get_i64_array(&self, key: &str) -> Result<Vec<i64>>

source

pub fn put_f32_array(&self, key: &str, value: &[f32]) -> Result<()>

source

pub fn get_f32_array(&self, key: &str) -> Result<Vec<f32>>

source

pub fn put_f64_array(&self, key: &str, value: &[f64]) -> Result<()>

source

pub fn get_f64_array(&self, key: &str) -> Result<Vec<f64>>

source

pub fn delete(&self, key: &str) -> Result<()>

source

pub fn clear_data(&self)

Clear all data.

source

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}");
    }
}
source

pub fn set_log_level(level: LogLevel)

Set log level to mmkv:

The default log level is LogLevel::Verbose.

Trait Implementations§

source§

impl Drop for MMKV

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.