pub struct KVDB<S: NorFlash> { /* private fields */ }Implementations§
Source§impl KVDB<StdStorage>
impl KVDB<StdStorage>
Sourcepub fn new_file(
name: &str,
path: &str,
sec_size: u32,
max_size: u32,
default_kvs: Option<&'static fdb_default_kv>,
) -> Result<Box<Self>, Error>
pub fn new_file( name: &str, path: &str, sec_size: u32, max_size: u32, default_kvs: Option<&'static fdb_default_kv>, ) -> Result<Box<Self>, Error>
在 std 环境下,创建一个基于文件的 KVDB 实例。
此函数返回一个 Box<KVDB<StdStorage>>,以确保数据库实例在内存中的地址是稳定的,
防止因栈帧移动导致传递给 C 库的内部指针失效。
§参数
name: 数据库名称path: 数据库文件存储的目录sec_size: 扇区大小max_size: 数据库最大容量default_kvs: 可选的默认键值对
Source§impl<S: NorFlash> KVDB<S>
impl<S: NorFlash> KVDB<S>
Sourcepub fn new(storage: S) -> Self
pub fn new(storage: S) -> Self
创建一个未初始化的 KVDB 实例。
在 no_std 环境下,这是创建数据库实例的主要方式。
实例创建后,必须调用 .init() 方法才能使用。
§参数
storage- 一个实现了embedded_storage::nor_flash::NorFlashtrait 的存储后端实例。
Sourcepub fn set_name(&mut self, name: &str) -> Result<(), Error>
pub fn set_name(&mut self, name: &str) -> Result<(), Error>
设置数据库名称,仅用于日志输出。
注意: 此方法必须在 init() 之前调用。
Sourcepub fn set_not_formatable(&mut self, enable: bool)
pub fn set_not_formatable(&mut self, enable: bool)
设置数据库为不可格式化模式。
在此模式下,如果数据库初始化时发现头部信息损坏,将返回错误而不是自动格式化。
注意: 此方法必须在 init() 之前调用。
Sourcepub fn not_formatable(&mut self) -> bool
pub fn not_formatable(&mut self) -> bool
检查数据库是否处于不可格式化模式。
Source§impl<S: NorFlash> KVDB<S>
impl<S: NorFlash> KVDB<S>
Sourcepub fn delete(&mut self, key: &str) -> Result<(), Error>
pub fn delete(&mut self, key: &str) -> Result<(), Error>
删除一个键值对。
这是一个逻辑删除,数据占用的空间将在未来的垃圾回收 (GC) 过程中被回收。
Sourcepub fn reset(&mut self) -> Result<(), Error>
pub fn reset(&mut self) -> Result<(), Error>
重置数据库到其默认状态。
如果初始化时提供了默认键值对,数据库将恢复到这些值。 否则,数据库将被清空。
警告: 此操作会删除所有当前数据。
Sourcepub fn get_reader<'a>(&mut self, key: &str) -> Result<KVReader<'_, S>, Error>
pub fn get_reader<'a>(&mut self, key: &str) -> Result<KVReader<'_, S>, Error>
获取一个用于流式读取键值的 KVReader。
这对于读取大尺寸的值非常有用,可以避免一次性将整个值加载到内存中。
pub fn iter(&mut self) -> KVDBIterator<'_, S> ⓘ
Trait Implementations§
Auto Trait Implementations§
impl<S> Freeze for KVDB<S>where
S: Freeze,
impl<S> RefUnwindSafe for KVDB<S>where
S: RefUnwindSafe,
impl<S> !Send for KVDB<S>
impl<S> !Sync for KVDB<S>
impl<S> Unpin for KVDB<S>where
S: Unpin,
impl<S> UnwindSafe for KVDB<S>where
S: UnwindSafe,
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