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
//! Rust version of MMKV.
//! Examples:
//! ```
//! use mmkv::MMKV;
//!
//! let temp_dir = std::env::temp_dir();
//! let mmkv = MMKV::new(temp_dir.to_str().unwrap(), #[cfg(feature = "encryption")] "88C51C536176AD8A8EE4A06F62EE897E");
//! mmkv.put_i32("key1", 1).unwrap();
//! assert_eq!(mmkv.get_i32("key1"), Ok(1));
//! // Not actually needed unless you intend to delete all data
//! mmkv.clear_data();
//! ```
//! For detailed API doc, see [MMKV]
pub use crate::log::LogLevel;
pub use crate::log::Logger;
pub use crate::mmkv::MMKV;

#[derive(Debug, PartialEq)]
pub enum Error {
    KeyNotFound,
    DecodeFailed(String),
    TypeMissMatch,
    DataInvalid,
    InstanceClosed,
    EncodeFailed(String),
    IOError(String),
    LockError(String),
    #[cfg(feature = "encryption")]
    DecryptFailed(String),
    #[cfg(feature = "encryption")]
    EncryptFailed(String),
}

pub type Result<T> = std::result::Result<T, Error>;

macro_rules! log {
    ($level:expr, $tag:expr, $($arg:tt)+) => {
        crate::log::logger::log($level, $tag, format_args!($($arg)+))
    }
}

macro_rules! error {
    ($tag:expr, $($arg:tt)+) => {
        log!(crate::LogLevel::Error, $tag, $($arg)+)
    }
}

#[allow(unused_macros)]
macro_rules! warn {
    ($tag:expr, $($arg:tt)+) => {
        log!(crate::LogLevel::Warn, $tag, $($arg)+)
    }
}

macro_rules! info {
    ($tag:expr, $($arg:tt)+) => {
        log!(crate::LogLevel::Info, $tag, $($arg)+)
    }
}

macro_rules! debug {
    ($tag:expr, $($arg:tt)+) => {
        log!(crate::LogLevel::Debug, $tag, $($arg)+)
    }
}

macro_rules! verbose {
    ($tag:expr, $($arg:tt)+) => {
        log!(crate::LogLevel::Verbose, $tag, $($arg)+)
    }
}

mod core;
#[cfg(not(target_os = "android"))]
#[cfg(not(feature = "encryption"))]
/// Expose the C API
mod ffi;
#[cfg(target_os = "android")]
/// Expose the JNI interface for android
mod jni;
mod log;
mod mmkv;