wasm_pkg_common/
registry.rs1use http::uri::Authority;
2use serde::{Deserialize, Serialize};
3
4use crate::Error;
5
6#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
10#[serde(into = "String", try_from = "String")]
11pub struct Registry(Authority);
12
13impl Registry {
14 pub fn host(&self) -> &str {
16 self.0.host()
17 }
18
19 pub fn port(&self) -> Option<u16> {
21 self.0.port_u16()
22 }
23}
24
25impl AsRef<str> for Registry {
26 fn as_ref(&self) -> &str {
27 self.0.as_str()
28 }
29}
30
31impl std::fmt::Display for Registry {
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 write!(f, "{}", self.0)
34 }
35}
36
37impl From<Registry> for String {
38 fn from(value: Registry) -> Self {
39 value.to_string()
40 }
41}
42
43impl std::str::FromStr for Registry {
44 type Err = Error;
45
46 fn from_str(s: &str) -> Result<Self, Self::Err> {
47 Ok(Self(s.parse()?))
48 }
49}
50
51impl TryFrom<String> for Registry {
52 type Error = Error;
53
54 fn try_from(value: String) -> Result<Self, Self::Error> {
55 Ok(Self(value.try_into()?))
56 }
57}