wedb_embed 0.1.1

Embedded database engine providing Redis-like APIs, built on fjall / 嵌入式数据库引擎,提供类似 Redis 的接口,底层基于 fjall 开发
Documentation
pub use crate::error::ERR_WRONG_TYPE;
pub const ERR_NO_SUCH_KEY: &str = "ERR no such key";
pub const ERR_INDEX_OUT_OF_RANGE: &str = "ERR index out of range";
pub const ERR_RANK_ZERO: &str = "ERR RANK can't be zero: must be 1, 2, 3, ... or -1, -2, -3...";

/// LPOS 选项配置(对标 Apache Kvrocks PosSpec)
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PosSpec {
    /// 匹配项序号(1 为第 1 个,-1 为倒数第 1 个,禁止为 0)
    pub rank: i64,
    /// 最多返回的匹配项数量(None 表示返回单个匹配,Some(0) 表示返回全部匹配,Some(N) 表示返回最多 N 个匹配)
    pub count: Option<usize>,
    /// 最大扫描元素数(0 或 None 表示全量扫描)
    pub max_len: Option<usize>,
}

impl PosSpec {
    #[inline]
    pub const fn new() -> Self {
        Self {
            rank: 1,
            count: None,
            max_len: None,
        }
    }

    #[inline]
    pub const fn with_rank(mut self, rank: i64) -> Self {
        self.rank = rank;
        self
    }

    #[inline]
    pub const fn with_count(mut self, count: usize) -> Self {
        self.count = Some(count);
        self
    }

    #[inline]
    pub const fn with_max_len(mut self, max_len: usize) -> Self {
        self.max_len = Some(max_len);
        self
    }
}

impl Default for PosSpec {
    #[inline]
    fn default() -> Self {
        Self::new()
    }
}