surrealdb/key/index/
all.rs1use crate::key::error::KeyCategory;
3use crate::key::key_req::KeyRequirements;
4use derive::Key;
5use serde::{Deserialize, Serialize};
6
7#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
8pub struct All<'a> {
9 __: u8,
10 _a: u8,
11 pub ns: &'a str,
12 _b: u8,
13 pub db: &'a str,
14 _c: u8,
15 pub tb: &'a str,
16 _d: u8,
17 pub ix: &'a str,
18}
19
20pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> All<'a> {
21 All::new(ns, db, tb, ix)
22}
23
24impl KeyRequirements for All<'_> {
25 fn key_category(&self) -> KeyCategory {
26 KeyCategory::IndexRoot
27 }
28}
29
30impl<'a> All<'a> {
31 pub fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> Self {
32 Self {
33 __: b'/',
34 _a: b'*',
35 ns,
36 _b: b'*',
37 db,
38 _c: b'*',
39 tb,
40 _d: b'+',
41 ix,
42 }
43 }
44}
45
46#[cfg(test)]
47mod tests {
48 #[test]
49 fn key() {
50 use super::*;
51 #[rustfmt::skip]
52 let val = All::new(
53 "testns",
54 "testdb",
55 "testtb",
56 "testix",
57 );
58 let enc = All::encode(&val).unwrap();
59 assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0+testix\0");
60
61 let dec = All::decode(&enc).unwrap();
62 assert_eq!(val, dec);
63 }
64}