slices_lexicon/
types.rs

1use serde_json::Value;
2
3/// Represents a loaded lexicon document
4#[derive(Debug, Clone)]
5pub struct LexiconDoc {
6    pub id: String,
7    pub defs: Value,
8}
9
10impl LexiconDoc {
11    pub fn id(&self) -> &str {
12        &self.id
13    }
14}
15
16/// String format types supported by AT Protocol (per lexicon spec)
17#[derive(Debug, Clone, PartialEq)]
18pub enum StringFormat {
19    DateTime,
20    Uri,
21    AtUri,
22    Did,
23    Handle,
24    AtIdentifier, // Can be either a Handle or a DID
25    Nsid,
26    Cid,
27    Language,
28    Tid,
29    RecordKey,
30}
31
32use std::str::FromStr;
33
34impl FromStr for StringFormat {
35    type Err = String;
36
37    fn from_str(s: &str) -> Result<Self, Self::Err> {
38        match s {
39            "datetime" => Ok(Self::DateTime),
40            "uri" => Ok(Self::Uri),
41            "at-uri" => Ok(Self::AtUri),
42            "did" => Ok(Self::Did),
43            "handle" => Ok(Self::Handle),
44            "at-identifier" => Ok(Self::AtIdentifier),
45            "nsid" => Ok(Self::Nsid),
46            "cid" => Ok(Self::Cid),
47            "language" => Ok(Self::Language),
48            "tid" => Ok(Self::Tid),
49            "record-key" => Ok(Self::RecordKey),
50            _ => Err(format!("Unknown string format: {}", s)),
51        }
52    }
53}