Skip to main content

surrealdb_core/key/node/
all.rs

1//! Stores the key prefix for all nodes
2use serde::{Deserialize, Serialize};
3use uuid::Uuid;
4
5use crate::key::category::{Categorise, Category};
6use crate::kvs::KVKey;
7
8#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
9pub(crate) struct All {
10	__: u8,
11	_a: u8,
12	#[serde(with = "uuid::serde::compact")]
13	pub nd: Uuid,
14}
15
16impl KVKey for All {
17	type ValueType = Vec<u8>;
18}
19
20pub fn new(nd: Uuid) -> All {
21	All::new(nd)
22}
23
24impl Categorise for All {
25	fn categorise(&self) -> Category {
26		Category::NodeRoot
27	}
28}
29
30impl All {
31	pub fn new(nd: Uuid) -> Self {
32		Self {
33			__: b'/',
34			_a: b'$',
35			nd,
36		}
37	}
38}
39
40#[cfg(test)]
41mod tests {
42	use super::*;
43
44	#[test]
45	fn key() {
46		#[rustfmt::skip]
47		let nd = Uuid::from_bytes([0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10]);
48		#[rustfmt::skip]
49		let val = All::new(
50			nd,
51		);
52		let enc = All::encode_key(&val).unwrap();
53		assert_eq!(enc, b"/$\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10");
54	}
55}