1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use ;
use Hash;
use FromStr;
/// A type-safe label for resource types.
///
/// Implementations discriminate between different kinds of resources in the store.
/// Typically generated from protobuf `google.api.resource` annotations.
///
/// The label is used as a discriminant in the [`Object<L>`][crate::Object] type
/// and for routing operations to the correct backend or handler.
///
/// # Trait bounds
///
/// The supertraits constrain what a label can do, so the store can treat it as a
/// lightweight, freely-copied key:
///
/// - [`Copy`] + [`Clone`] — labels are passed by value throughout the store API;
/// being trivially copyable keeps those calls cheap and allocation-free.
/// - [`Hash`] + [`Eq`] — labels are used as map keys when routing operations and
/// grouping objects by type.
/// - [`Display`] + [`FromStr`] — labels round-trip to and from their string form
/// for serialization and wire protocols.
/// - [`Debug`] — labels appear in error messages and `tracing` output.
/// - [`Send`] + [`Sync`] + `'static` — labels cross `async` task and thread
/// boundaries and are held inside stores that may outlive any single request.
///
/// # Examples
///
/// A minimal label enum distinguishing two resource types:
///
/// ```
/// use std::fmt;
/// use std::str::FromStr;
///
/// use olai_store::Label;
///
/// #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
/// enum Kind {
/// Folder,
/// File,
/// }
///
/// impl fmt::Display for Kind {
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
/// f.write_str(self.as_str())
/// }
/// }
///
/// impl FromStr for Kind {
/// type Err = String;
///
/// fn from_str(s: &str) -> Result<Self, Self::Err> {
/// match s {
/// "folder" => Ok(Kind::Folder),
/// "file" => Ok(Kind::File),
/// other => Err(format!("unknown kind: {other}")),
/// }
/// }
/// }
///
/// impl Label for Kind {
/// fn as_str(&self) -> &str {
/// match self {
/// Kind::Folder => "folder",
/// Kind::File => "file",
/// }
/// }
/// }
///
/// assert_eq!(Kind::File.as_str(), "file");
/// assert_eq!("folder".parse::<Kind>(), Ok(Kind::Folder));
/// ```