surrealpatch/lib/src/key/namespace.rs

39 lines
648 B
Rust
Raw Normal View History

2022-06-15 07:41:23 +00:00
use derive::Key;
use serde::{Deserialize, Serialize};
2022-06-15 07:41:23 +00:00
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
pub struct Namespace {
__: u8,
_a: u8,
2022-03-07 12:25:40 +00:00
pub ns: String,
}
pub fn new(ns: &str) -> Namespace {
Namespace::new(ns.to_string())
}
impl Namespace {
pub fn new(ns: String) -> Namespace {
Namespace {
__: 0x2f, // /
_a: 0x2a, // *
ns,
}
}
}
#[cfg(test)]
mod tests {
#[test]
fn key() {
use super::*;
#[rustfmt::skip]
let val = Namespace::new(
"test".to_string(),
);
let enc = Namespace::encode(&val).unwrap();
let dec = Namespace::decode(&enc).unwrap();
assert_eq!(val, dec);
}
}