Skip to main content

co_primitives/types/
co.rs

1// SPDX-License-Identifier: AGPL-3.0-only
2// Copyright (C) 2026 1io BRANDGUARDIAN GmbH
3
4use super::tags::TagValue;
5use serde::{Deserialize, Serialize};
6use std::{borrow::Borrow, fmt::Display, ops::Deref};
7
8/// CO Unique ID.
9#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Hash)]
10pub struct CoId(String);
11impl CoId {
12	pub fn new(co: impl Into<String>) -> Self {
13		Self(co.into())
14	}
15
16	pub fn as_str(&self) -> &str {
17		&self.0
18	}
19}
20impl From<String> for CoId {
21	fn from(value: String) -> Self {
22		Self(value)
23	}
24}
25impl From<&str> for CoId {
26	fn from(value: &str) -> Self {
27		Self(value.to_owned())
28	}
29}
30impl From<&String> for CoId {
31	fn from(value: &String) -> Self {
32		Self(value.to_owned())
33	}
34}
35impl From<&CoId> for CoId {
36	fn from(value: &CoId) -> Self {
37		value.to_owned()
38	}
39}
40impl From<CoId> for String {
41	fn from(val: CoId) -> Self {
42		val.0
43	}
44}
45impl From<CoId> for TagValue {
46	fn from(val: CoId) -> Self {
47		val.0.into()
48	}
49}
50impl AsRef<str> for CoId {
51	fn as_ref(&self) -> &str {
52		&self.0
53	}
54}
55impl AsRef<CoId> for CoId {
56	fn as_ref(&self) -> &CoId {
57		self
58	}
59}
60impl Display for CoId {
61	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62		f.write_str(&self.0)
63	}
64}
65impl Borrow<str> for CoId {
66	fn borrow(&self) -> &str {
67		&self.0
68	}
69}
70impl Deref for CoId {
71	type Target = str;
72
73	fn deref(&self) -> &Self::Target {
74		&self.0
75	}
76}