1use url::Url;
2
3pub trait UrlLike {
4 fn new(url: Url) -> Self;
5 fn from_string(s: String) -> Self;
6 fn as_str(&self) -> &str;
7 fn to_string(self) -> String;
8}
9
10#[derive(Debug, Clone, PartialEq, Eq)]
12#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13#[cfg_attr(
14 feature = "rkyv",
15 derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
16)]
17#[cfg_attr(feature = "rkyv", rkyv(derive(Debug, PartialEq, Eq, Hash)))]
18pub struct MovieURL(String);
19
20impl UrlLike for MovieURL {
21 fn new(url: Url) -> Self {
22 MovieURL(url.to_string())
23 }
24
25 fn from_string(s: String) -> Self {
26 MovieURL(s)
27 }
28
29 fn as_str(&self) -> &str {
30 &self.0
31 }
32 fn to_string(self) -> String {
33 self.0
34 }
35}
36
37impl std::fmt::Display for MovieURL {
38 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39 write!(f, "{}", self.0)
40 }
41}
42
43#[cfg(feature = "rkyv")]
44impl std::fmt::Display for ArchivedMovieURL {
45 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46 write!(f, "{}", self.0.as_str())
47 }
48}
49
50impl From<String> for MovieURL {
51 fn from(s: String) -> Self {
52 MovieURL(s)
53 }
54}
55
56impl AsRef<str> for MovieURL {
57 fn as_ref(&self) -> &str {
58 &self.0
59 }
60}
61
62impl std::hash::Hash for MovieURL {
63 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
64 self.0.hash(state);
65 }
66}
67
68#[derive(Debug, Clone, PartialEq, Eq)]
70#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
71#[cfg_attr(
72 feature = "rkyv",
73 derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
74)]
75#[cfg_attr(feature = "rkyv", rkyv(derive(Debug, PartialEq, Eq, Hash)))]
76pub struct SeriesURL(String);
77
78impl SeriesURL {
79 pub fn new(url: Url) -> Self {
80 SeriesURL(url.to_string())
81 }
82
83 pub fn from_string(s: String) -> Self {
84 SeriesURL(s)
85 }
86
87 pub fn as_str(&self) -> &str {
88 &self.0
89 }
90}
91
92impl std::fmt::Display for SeriesURL {
93 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
94 write!(f, "{}", self.0)
95 }
96}
97#[cfg(feature = "rkyv")]
98impl std::fmt::Display for ArchivedSeriesURL {
99 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
100 write!(f, "{}", self.0.as_str())
101 }
102}
103
104impl From<String> for SeriesURL {
105 fn from(s: String) -> Self {
106 SeriesURL(s)
107 }
108}
109
110impl AsRef<str> for SeriesURL {
111 fn as_ref(&self) -> &str {
112 &self.0
113 }
114}
115
116impl std::hash::Hash for SeriesURL {
117 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
118 self.0.hash(state);
119 }
120}
121
122#[derive(Debug, Clone, PartialEq, Eq)]
124#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
125#[cfg_attr(
126 feature = "rkyv",
127 derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
128)]
129#[cfg_attr(feature = "rkyv", rkyv(derive(Debug, PartialEq, Eq, Hash)))]
130pub struct SeasonURL(String);
131
132impl SeasonURL {
133 pub fn new(url: Url) -> Self {
134 SeasonURL(url.to_string())
135 }
136
137 pub fn from_string(s: String) -> Self {
138 SeasonURL(s)
139 }
140
141 pub fn as_str(&self) -> &str {
142 &self.0
143 }
144}
145
146impl std::fmt::Display for SeasonURL {
147 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
148 write!(f, "{}", self.0)
149 }
150}
151#[cfg(feature = "rkyv")]
152impl std::fmt::Display for ArchivedSeasonURL {
153 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
154 write!(f, "{}", self.0.as_str())
155 }
156}
157
158impl From<String> for SeasonURL {
159 fn from(s: String) -> Self {
160 SeasonURL(s)
161 }
162}
163
164impl AsRef<str> for SeasonURL {
165 fn as_ref(&self) -> &str {
166 &self.0
167 }
168}
169
170impl std::hash::Hash for SeasonURL {
171 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
172 self.0.hash(state);
173 }
174}
175
176#[derive(Debug, Clone, PartialEq, Eq)]
178#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
179#[cfg_attr(
180 feature = "rkyv",
181 derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
182)]
183#[cfg_attr(feature = "rkyv", rkyv(derive(Debug, PartialEq, Eq, Hash)))]
184pub struct EpisodeURL(String);
185
186impl EpisodeURL {
187 pub fn new(url: Url) -> Self {
188 EpisodeURL(url.to_string())
189 }
190
191 pub fn from_string(s: String) -> Self {
192 EpisodeURL(s)
193 }
194
195 pub fn as_str(&self) -> &str {
196 &self.0
197 }
198}
199
200impl std::fmt::Display for EpisodeURL {
201 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
202 write!(f, "{}", self.0)
203 }
204}
205#[cfg(feature = "rkyv")]
206impl std::fmt::Display for ArchivedEpisodeURL {
207 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
208 write!(f, "{}", self.0.as_str())
209 }
210}
211
212impl From<String> for EpisodeURL {
213 fn from(s: String) -> Self {
214 EpisodeURL(s)
215 }
216}
217
218impl AsRef<str> for EpisodeURL {
219 fn as_ref(&self) -> &str {
220 &self.0
221 }
222}
223
224impl std::hash::Hash for EpisodeURL {
225 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
226 self.0.hash(state);
227 }
228}