tauri_store/store/
id.rs

1use serde::{Deserialize, Serialize};
2use std::borrow::Cow;
3use std::fmt;
4use std::sync::Arc;
5
6/// Unique identifier for a store.
7#[derive(Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
8pub struct StoreId(Arc<str>);
9
10impl StoreId {
11  pub fn new(id: &str) -> Self {
12    Self::from(id)
13  }
14}
15
16impl AsRef<str> for StoreId {
17  fn as_ref(&self) -> &str {
18    &self.0
19  }
20}
21
22impl Clone for StoreId {
23  fn clone(&self) -> Self {
24    Self(Arc::clone(&self.0))
25  }
26}
27
28impl From<&StoreId> for StoreId {
29  fn from(value: &StoreId) -> Self {
30    value.clone()
31  }
32}
33
34impl From<&str> for StoreId {
35  fn from(id: &str) -> Self {
36    Self(Arc::from(id))
37  }
38}
39
40impl From<String> for StoreId {
41  fn from(id: String) -> Self {
42    Self(Arc::from(id))
43  }
44}
45
46impl From<&String> for StoreId {
47  fn from(id: &String) -> Self {
48    Self(Arc::from(id.as_str()))
49  }
50}
51
52impl From<Arc<str>> for StoreId {
53  fn from(id: Arc<str>) -> Self {
54    Self::from(id.as_ref())
55  }
56}
57
58impl From<Box<str>> for StoreId {
59  fn from(id: Box<str>) -> Self {
60    Self::from(id.as_ref())
61  }
62}
63
64impl From<Cow<'_, str>> for StoreId {
65  fn from(id: Cow<'_, str>) -> Self {
66    Self::from(id.as_ref())
67  }
68}
69
70impl fmt::Display for StoreId {
71  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
72    write!(f, "{}", self.0)
73  }
74}