aa_storage/driver_name.rs
1//! [`DriverName`] — the string identifier that selects a storage backend.
2
3use std::fmt;
4
5use serde::{Deserialize, Serialize};
6
7/// Name of a storage driver as written in `agent-assembly.toml`
8/// (e.g. `"redis"`, `"postgres"`, `"memory"`).
9///
10/// A `DriverName` is the key the [`Registry`](crate::Registry) resolves to a
11/// concrete backend factory, and also the key of the per-driver
12/// `[storage.<name>]` subsection. It is a thin, transparent newtype over
13/// [`String`] so it deserializes directly from a TOML string and can be used as
14/// a map key.
15///
16/// ```
17/// use aa_storage::DriverName;
18///
19/// let name = DriverName::new("redis");
20/// assert_eq!(name.as_str(), "redis");
21/// ```
22#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
23#[serde(transparent)]
24pub struct DriverName(String);
25
26impl DriverName {
27 /// Create a `DriverName` from anything string-like.
28 pub fn new(name: impl Into<String>) -> Self {
29 Self(name.into())
30 }
31
32 /// Borrow the underlying driver name as a string slice.
33 pub fn as_str(&self) -> &str {
34 &self.0
35 }
36}
37
38impl fmt::Display for DriverName {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 f.write_str(&self.0)
41 }
42}
43
44impl From<&str> for DriverName {
45 fn from(s: &str) -> Self {
46 Self(s.to_string())
47 }
48}
49
50impl From<String> for DriverName {
51 fn from(s: String) -> Self {
52 Self(s)
53 }
54}