Skip to main content

feedparser_rs/types/
common.rs

1use super::generics::{FromAttributes, ParseFrom};
2use crate::util::date::parse_date;
3use compact_str::CompactString;
4use jiff::Timestamp;
5use serde_json::Value;
6use std::collections::HashMap;
7use std::ops::Deref;
8use std::sync::Arc;
9
10/// Optimized string type for small strings (≤24 bytes stored inline)
11///
12/// Uses `CompactString` which stores strings up to 24 bytes inline without heap allocation.
13/// This significantly reduces allocations for common short strings like language codes,
14/// author names, category terms, and other metadata fields.
15///
16/// `CompactString` implements `Deref<Target=str>`, so it can be used transparently as a string.
17///
18/// # Examples
19///
20/// ```
21/// use feedparser_rs::types::SmallString;
22///
23/// let s: SmallString = "en-US".into();
24/// assert_eq!(s.as_str(), "en-US");
25/// assert_eq!(s.len(), 5); // Stored inline, no heap allocation
26/// ```
27pub type SmallString = CompactString;
28
29/// URL newtype for type-safe URL handling
30///
31/// Provides a semantic wrapper around string URLs without validation.
32/// Following the bozo pattern, URLs are not validated during parsing.
33///
34/// # Examples
35///
36/// ```
37/// use feedparser_rs::Url;
38///
39/// let url = Url::new("https://example.com");
40/// assert_eq!(url.as_str(), "https://example.com");
41///
42/// // Deref coercion allows transparent string access
43/// let len: usize = url.len();
44/// assert_eq!(len, 19);
45/// ```
46#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, serde::Serialize, serde::Deserialize)]
47#[serde(transparent)]
48pub struct Url(String);
49
50impl Url {
51    /// Creates a new URL from any type that can be converted to a String
52    ///
53    /// # Examples
54    ///
55    /// ```
56    /// use feedparser_rs::Url;
57    ///
58    /// let url1 = Url::new("https://example.com");
59    /// let url2 = Url::new(String::from("https://example.com"));
60    /// assert_eq!(url1, url2);
61    /// ```
62    #[inline]
63    pub fn new(s: impl Into<String>) -> Self {
64        Self(s.into())
65    }
66
67    /// Returns the URL as a string slice
68    ///
69    /// # Examples
70    ///
71    /// ```
72    /// use feedparser_rs::Url;
73    ///
74    /// let url = Url::new("https://example.com");
75    /// assert_eq!(url.as_str(), "https://example.com");
76    /// ```
77    #[inline]
78    pub fn as_str(&self) -> &str {
79        &self.0
80    }
81
82    /// Consumes the `Url` and returns the inner `String`
83    ///
84    /// # Examples
85    ///
86    /// ```
87    /// use feedparser_rs::Url;
88    ///
89    /// let url = Url::new("https://example.com");
90    /// let inner: String = url.into_inner();
91    /// assert_eq!(inner, "https://example.com");
92    /// ```
93    #[inline]
94    pub fn into_inner(self) -> String {
95        self.0
96    }
97}
98
99impl Deref for Url {
100    type Target = str;
101
102    #[inline]
103    fn deref(&self) -> &str {
104        &self.0
105    }
106}
107
108impl From<String> for Url {
109    #[inline]
110    fn from(s: String) -> Self {
111        Self(s)
112    }
113}
114
115impl From<&str> for Url {
116    #[inline]
117    fn from(s: &str) -> Self {
118        Self(s.to_string())
119    }
120}
121
122impl AsRef<str> for Url {
123    #[inline]
124    fn as_ref(&self) -> &str {
125        &self.0
126    }
127}
128
129impl std::fmt::Display for Url {
130    #[inline]
131    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
132        self.0.fmt(f)
133    }
134}
135
136impl PartialEq<str> for Url {
137    fn eq(&self, other: &str) -> bool {
138        self.0 == other
139    }
140}
141
142impl PartialEq<&str> for Url {
143    fn eq(&self, other: &&str) -> bool {
144        self.0 == *other
145    }
146}
147
148impl PartialEq<String> for Url {
149    fn eq(&self, other: &String) -> bool {
150        &self.0 == other
151    }
152}
153
154/// MIME type newtype with string interning
155///
156/// Uses `Arc<str>` for efficient cloning of common MIME types.
157/// Multiple references to the same MIME type share the same allocation.
158///
159/// # Examples
160///
161/// ```
162/// use feedparser_rs::MimeType;
163///
164/// let mime = MimeType::new("text/html");
165/// assert_eq!(mime.as_str(), "text/html");
166///
167/// // Cloning is cheap (just increments reference count)
168/// let clone = mime.clone();
169/// assert_eq!(mime, clone);
170/// ```
171#[derive(Debug, Clone, PartialEq, Eq, Hash)]
172pub struct MimeType(Arc<str>);
173
174// Custom serde implementation for MimeType since Arc<str> doesn't implement Serialize/Deserialize
175impl serde::Serialize for MimeType {
176    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
177    where
178        S: serde::Serializer,
179    {
180        serializer.serialize_str(&self.0)
181    }
182}
183
184impl<'de> serde::Deserialize<'de> for MimeType {
185    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
186    where
187        D: serde::Deserializer<'de>,
188    {
189        let s = <String as serde::Deserialize>::deserialize(deserializer)?;
190        Ok(Self::new(s))
191    }
192}
193
194impl MimeType {
195    /// Creates a new MIME type from any string-like type
196    ///
197    /// # Examples
198    ///
199    /// ```
200    /// use feedparser_rs::MimeType;
201    ///
202    /// let mime = MimeType::new("application/json");
203    /// assert_eq!(mime.as_str(), "application/json");
204    /// ```
205    #[inline]
206    pub fn new(s: impl AsRef<str>) -> Self {
207        Self(Arc::from(s.as_ref()))
208    }
209
210    /// Returns the MIME type as a string slice
211    ///
212    /// # Examples
213    ///
214    /// ```
215    /// use feedparser_rs::MimeType;
216    ///
217    /// let mime = MimeType::new("text/plain");
218    /// assert_eq!(mime.as_str(), "text/plain");
219    /// ```
220    #[inline]
221    pub fn as_str(&self) -> &str {
222        &self.0
223    }
224
225    /// Common MIME type constants for convenience.
226    ///
227    /// # Examples
228    ///
229    /// ```
230    /// use feedparser_rs::MimeType;
231    ///
232    /// let html = MimeType::new(MimeType::TEXT_HTML);
233    /// assert_eq!(html.as_str(), "text/html");
234    /// ```
235    pub const TEXT_HTML: &'static str = "text/html";
236
237    /// `text/plain` MIME type constant
238    pub const TEXT_PLAIN: &'static str = "text/plain";
239
240    /// `application/xml` MIME type constant
241    pub const APPLICATION_XML: &'static str = "application/xml";
242
243    /// `application/json` MIME type constant
244    pub const APPLICATION_JSON: &'static str = "application/json";
245}
246
247impl Default for MimeType {
248    #[inline]
249    fn default() -> Self {
250        Self(Arc::from(""))
251    }
252}
253
254impl Deref for MimeType {
255    type Target = str;
256
257    #[inline]
258    fn deref(&self) -> &str {
259        &self.0
260    }
261}
262
263impl From<String> for MimeType {
264    #[inline]
265    fn from(s: String) -> Self {
266        Self(Arc::from(s.as_str()))
267    }
268}
269
270impl From<&str> for MimeType {
271    #[inline]
272    fn from(s: &str) -> Self {
273        Self(Arc::from(s))
274    }
275}
276
277impl AsRef<str> for MimeType {
278    #[inline]
279    fn as_ref(&self) -> &str {
280        &self.0
281    }
282}
283
284impl std::fmt::Display for MimeType {
285    #[inline]
286    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
287        self.0.fmt(f)
288    }
289}
290
291impl PartialEq<str> for MimeType {
292    fn eq(&self, other: &str) -> bool {
293        &*self.0 == other
294    }
295}
296
297impl PartialEq<&str> for MimeType {
298    fn eq(&self, other: &&str) -> bool {
299        &*self.0 == *other
300    }
301}
302
303impl PartialEq<String> for MimeType {
304    fn eq(&self, other: &String) -> bool {
305        &*self.0 == other
306    }
307}
308
309/// Email newtype for type-safe email handling
310///
311/// Provides a semantic wrapper around email addresses without validation.
312/// Following the bozo pattern, emails are not validated during parsing.
313///
314/// # Examples
315///
316/// ```
317/// use feedparser_rs::Email;
318///
319/// let email = Email::new("user@example.com");
320/// assert_eq!(email.as_str(), "user@example.com");
321/// ```
322#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, serde::Serialize, serde::Deserialize)]
323#[serde(transparent)]
324pub struct Email(String);
325
326impl Email {
327    /// Creates a new email from any type that can be converted to a String
328    ///
329    /// # Examples
330    ///
331    /// ```
332    /// use feedparser_rs::Email;
333    ///
334    /// let email = Email::new("user@example.com");
335    /// assert_eq!(email.as_str(), "user@example.com");
336    /// ```
337    #[inline]
338    pub fn new(s: impl Into<String>) -> Self {
339        Self(s.into())
340    }
341
342    /// Returns the email as a string slice
343    ///
344    /// # Examples
345    ///
346    /// ```
347    /// use feedparser_rs::Email;
348    ///
349    /// let email = Email::new("user@example.com");
350    /// assert_eq!(email.as_str(), "user@example.com");
351    /// ```
352    #[inline]
353    pub fn as_str(&self) -> &str {
354        &self.0
355    }
356
357    /// Consumes the `Email` and returns the inner `String`
358    ///
359    /// # Examples
360    ///
361    /// ```
362    /// use feedparser_rs::Email;
363    ///
364    /// let email = Email::new("user@example.com");
365    /// let inner: String = email.into_inner();
366    /// assert_eq!(inner, "user@example.com");
367    /// ```
368    #[inline]
369    pub fn into_inner(self) -> String {
370        self.0
371    }
372}
373
374impl Deref for Email {
375    type Target = str;
376
377    #[inline]
378    fn deref(&self) -> &str {
379        &self.0
380    }
381}
382
383impl From<String> for Email {
384    #[inline]
385    fn from(s: String) -> Self {
386        Self(s)
387    }
388}
389
390impl From<&str> for Email {
391    #[inline]
392    fn from(s: &str) -> Self {
393        Self(s.to_string())
394    }
395}
396
397impl AsRef<str> for Email {
398    #[inline]
399    fn as_ref(&self) -> &str {
400        &self.0
401    }
402}
403
404impl std::fmt::Display for Email {
405    #[inline]
406    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
407        self.0.fmt(f)
408    }
409}
410
411impl PartialEq<str> for Email {
412    fn eq(&self, other: &str) -> bool {
413        self.0 == other
414    }
415}
416
417impl PartialEq<&str> for Email {
418    fn eq(&self, other: &&str) -> bool {
419        self.0 == *other
420    }
421}
422
423impl PartialEq<String> for Email {
424    fn eq(&self, other: &String) -> bool {
425        &self.0 == other
426    }
427}
428
429/// Link in feed or entry
430#[derive(Debug, Clone, Default)]
431#[non_exhaustive]
432pub struct Link {
433    /// Link URL
434    pub href: Url,
435    /// Link relationship type (e.g., "alternate", "enclosure", "self")
436    /// Stored inline as these are typically short (≤24 bytes)
437    pub rel: Option<SmallString>,
438    /// MIME type of the linked resource
439    pub link_type: Option<MimeType>,
440    /// Human-readable link title
441    pub title: Option<String>,
442    /// Length of the linked resource in bytes (raw string value, as in Python feedparser)
443    pub length: Option<String>,
444    /// Language of the linked resource (stored inline for lang codes ≤24 bytes)
445    pub hreflang: Option<SmallString>,
446    /// RFC 4685 §4: number of replies at the IRI
447    pub thr_count: Option<u32>,
448    /// RFC 4685 §4: when the reply resource was last modified
449    pub thr_updated: Option<Timestamp>,
450    /// Custom JSON Feed `_`-prefixed members of this hub.
451    ///
452    /// Captured under the same caps as [`super::entry::Entry::json_extensions`];
453    /// empty for every other format.
454    pub json_extensions: HashMap<String, Value>,
455}
456
457impl Link {
458    /// Create a new link with just URL and relation type
459    #[inline]
460    pub fn new(href: impl Into<Url>, rel: impl AsRef<str>) -> Self {
461        Self {
462            href: href.into(),
463            rel: Some(rel.as_ref().into()),
464            link_type: None,
465            title: None,
466            length: None,
467            hreflang: None,
468            thr_count: None,
469            thr_updated: None,
470            ..Self::default()
471        }
472    }
473
474    /// Create an alternate link (common for entry URLs)
475    #[inline]
476    pub fn alternate(href: impl Into<Url>) -> Self {
477        Self::new(href, "alternate")
478    }
479
480    /// Create a self link (for feed URLs)
481    #[inline]
482    pub fn self_link(href: impl Into<Url>, mime_type: impl Into<MimeType>) -> Self {
483        Self {
484            href: href.into(),
485            rel: Some("self".into()),
486            link_type: Some(mime_type.into()),
487            title: None,
488            length: None,
489            hreflang: None,
490            thr_count: None,
491            thr_updated: None,
492            ..Self::default()
493        }
494    }
495
496    /// Create an enclosure link (for media)
497    #[inline]
498    pub fn enclosure(href: impl Into<Url>, mime_type: Option<MimeType>) -> Self {
499        Self {
500            href: href.into(),
501            rel: Some("enclosure".into()),
502            link_type: mime_type,
503            title: None,
504            length: None,
505            hreflang: None,
506            thr_count: None,
507            thr_updated: None,
508            ..Self::default()
509        }
510    }
511
512    /// Create a related link
513    #[inline]
514    pub fn related(href: impl Into<Url>) -> Self {
515        Self::new(href, "related")
516    }
517
518    /// Create a banner image link (JSON Feed `banner_image`, project-internal convention)
519    ///
520    /// Note: `rel="banner"` is not a standard link relation. It is used here as a project
521    /// convention to store JSON Feed `banner_image` in the existing `Link` type. Consumers
522    /// must search `entry.links` for `rel="banner"` to retrieve this field.
523    #[inline]
524    pub fn banner(href: impl Into<Url>) -> Self {
525        Self::new(href, "banner")
526    }
527
528    /// Create a hub link (JSON Feed 1.1 `hubs` array, `WebSub` convention)
529    #[inline]
530    pub fn hub(href: impl Into<Url>) -> Self {
531        Self::new(href, "hub")
532    }
533
534    /// Set MIME type (builder pattern)
535    #[inline]
536    #[must_use]
537    pub fn with_type(mut self, mime_type: impl Into<MimeType>) -> Self {
538        self.link_type = Some(mime_type.into());
539        self
540    }
541}
542
543/// Person (author, contributor, etc.)
544#[derive(Debug, Clone, Default)]
545#[non_exhaustive]
546pub struct Person {
547    /// Person's name (stored inline for names ≤24 bytes)
548    pub name: Option<SmallString>,
549    /// Person's email address
550    pub email: Option<Email>,
551    /// Person's URI/website
552    pub uri: Option<String>,
553    /// Person's avatar image URL (JSON Feed only)
554    pub avatar: Option<String>,
555    /// Custom JSON Feed `_`-prefixed members of this author.
556    ///
557    /// Captured under the same caps as [`super::entry::Entry::json_extensions`];
558    /// empty for every other format.
559    pub json_extensions: HashMap<String, Value>,
560}
561
562impl Person {
563    /// Create person from just a name
564    ///
565    /// # Examples
566    ///
567    /// ```
568    /// use feedparser_rs::types::Person;
569    ///
570    /// let person = Person::from_name("John Doe");
571    /// assert_eq!(person.name.as_deref(), Some("John Doe"));
572    /// assert!(person.email.is_none());
573    /// assert!(person.uri.is_none());
574    /// ```
575    #[inline]
576    pub fn from_name(name: impl AsRef<str>) -> Self {
577        Self {
578            name: Some(name.as_ref().into()),
579            email: None,
580            uri: None,
581            avatar: None,
582            ..Self::default()
583        }
584    }
585
586    /// Build flat author string in `"Name (email)"` format when email is present.
587    ///
588    /// Returns `None` if neither name nor email is set.
589    #[must_use]
590    pub fn flat_string(&self) -> Option<SmallString> {
591        match (&self.name, &self.email) {
592            (Some(name), Some(email)) => Some(format!("{name} ({email})").into()),
593            (Some(name), None) => Some(name.clone()),
594            (None, Some(email)) => Some(email.as_str().into()),
595            (None, None) => None,
596        }
597    }
598}
599
600/// Tag/category
601#[derive(Debug, Clone)]
602#[non_exhaustive]
603pub struct Tag {
604    /// Tag term/label (stored inline for terms ≤24 bytes)
605    pub term: SmallString,
606    /// Tag scheme/domain (stored inline for schemes ≤24 bytes)
607    pub scheme: Option<SmallString>,
608    /// Human-readable tag label (stored inline for labels ≤24 bytes)
609    pub label: Option<SmallString>,
610}
611
612impl Tag {
613    /// Create a simple tag with just term
614    #[inline]
615    pub fn new(term: impl AsRef<str>) -> Self {
616        Self {
617            term: term.as_ref().into(),
618            scheme: None,
619            label: None,
620        }
621    }
622}
623
624/// RSS 2.0 `<cloud>` element — subscription endpoint for updates
625#[derive(Debug, Default, Clone, PartialEq, Eq)]
626#[non_exhaustive]
627pub struct Cloud {
628    /// Domain of the cloud server
629    pub domain: Option<String>,
630    /// Port of the cloud server
631    pub port: Option<String>,
632    /// Path of the cloud server
633    pub path: Option<String>,
634    /// Procedure to register for update notifications
635    pub register_procedure: Option<String>,
636    /// Protocol: xml-rpc, soap, or http-post
637    pub protocol: Option<String>,
638}
639
640/// RSS 2.0 `<textInput>` element — text input form associated with the channel
641#[derive(Debug, Default, Clone, PartialEq, Eq)]
642#[non_exhaustive]
643pub struct TextInput {
644    /// Title of the Submit button in the text input area
645    pub title: Option<String>,
646    /// Explains the text input area
647    pub description: Option<String>,
648    /// The name of the text object in the text input area
649    pub name: Option<String>,
650    /// The URL of the CGI script that processes text input requests
651    pub link: Option<String>,
652}
653
654/// Image metadata
655#[derive(Debug, Clone)]
656#[non_exhaustive]
657pub struct Image {
658    /// Image URL
659    pub url: Url,
660    /// Image title
661    pub title: Option<String>,
662    /// Link associated with the image
663    pub link: Option<String>,
664    /// Image width in pixels
665    pub width: Option<u32>,
666    /// Image height in pixels
667    pub height: Option<u32>,
668    /// Image description
669    pub description: Option<String>,
670}
671
672impl Image {
673    /// Creates an `Image` from its required `url`; every other field is empty.
674    ///
675    /// # Examples
676    ///
677    /// ```
678    /// use feedparser_rs::Image;
679    ///
680    /// let image = Image::new("https://example.com/logo.png".into());
681    /// assert!(image.title.is_none());
682    /// ```
683    #[must_use]
684    pub const fn new(url: Url) -> Self {
685        Self {
686            url,
687            title: None,
688            link: None,
689            width: None,
690            height: None,
691            description: None,
692        }
693    }
694}
695
696/// Enclosure (attached media file)
697#[derive(Debug, Clone, Default)]
698#[non_exhaustive]
699pub struct Enclosure {
700    /// Enclosure URL
701    pub url: Url,
702    /// File size in bytes (raw string value, as in Python feedparser)
703    pub length: Option<String>,
704    /// MIME type
705    pub enclosure_type: Option<MimeType>,
706    /// Attachment title (JSON Feed only)
707    pub title: Option<String>,
708    /// Duration in seconds as raw string (JSON Feed `duration_in_seconds`)
709    pub duration: Option<String>,
710    /// Custom JSON Feed `_`-prefixed members of this attachment.
711    ///
712    /// Captured under the same caps as [`super::entry::Entry::json_extensions`];
713    /// empty for every other format.
714    pub json_extensions: HashMap<String, Value>,
715}
716
717impl Enclosure {
718    /// Creates an `Enclosure` from its required `url`; every other field is empty.
719    ///
720    /// # Examples
721    ///
722    /// ```
723    /// use feedparser_rs::Enclosure;
724    ///
725    /// let enclosure = Enclosure::new("https://example.com/ep.mp3".into());
726    /// assert!(enclosure.length.is_none());
727    /// ```
728    #[must_use]
729    pub fn new(url: Url) -> Self {
730        Self {
731            url,
732            ..Self::default()
733        }
734    }
735}
736
737/// Content block
738#[derive(Debug, Clone)]
739#[non_exhaustive]
740pub struct Content {
741    /// Content body
742    pub value: String,
743    /// Content MIME type
744    pub content_type: Option<MimeType>,
745    /// Content language (stored inline for lang codes ≤24 bytes)
746    pub language: Option<SmallString>,
747    /// Base URL for relative links
748    pub base: Option<String>,
749    /// Out-of-line content URL (Atom `<content src="...">`, RFC 4287 §4.1.3.2)
750    pub src: Option<String>,
751}
752
753impl Content {
754    /// Create HTML content
755    #[inline]
756    pub fn html(value: impl Into<String>) -> Self {
757        Self {
758            value: value.into(),
759            content_type: Some(MimeType::new(MimeType::TEXT_HTML)),
760            language: None,
761            base: None,
762            src: None,
763        }
764    }
765
766    /// Create plain text content
767    #[inline]
768    pub fn plain(value: impl Into<String>) -> Self {
769        Self {
770            value: value.into(),
771            content_type: Some(MimeType::new(MimeType::TEXT_PLAIN)),
772            language: None,
773            base: None,
774            src: None,
775        }
776    }
777}
778
779/// Text construct type (Atom-style)
780#[derive(Debug, Clone, Copy, PartialEq, Eq)]
781#[expect(
782    clippy::exhaustive_enums,
783    reason = "the text types are fixed by the Atom RFC 4287 and matched exhaustively by callers"
784)]
785pub enum TextType {
786    /// Plain text
787    Text,
788    /// HTML content
789    Html,
790    /// XHTML content
791    Xhtml,
792}
793
794impl TextType {
795    /// Determine the text type from an Atom `type` attribute value.
796    ///
797    /// Per RFC 4287 §3.1.1, the recognized values are `text`, `html`, and
798    /// `xhtml`; this also accepts the equivalent MIME spellings (`text/html`,
799    /// `application/xhtml+xml`) some feeds use in practice. Comparison is
800    /// case-insensitive. Any other value maps to `Html` — fail-closed, so a
801    /// bogus or unrecognized type label cannot be used to smuggle content past
802    /// downstream HTML sanitization by masquerading as plain text.
803    ///
804    /// # Examples
805    ///
806    /// ```
807    /// use feedparser_rs::types::TextType;
808    ///
809    /// assert_eq!(TextType::from_type_attr("text"), TextType::Text);
810    /// assert_eq!(TextType::from_type_attr("HTML"), TextType::Html);
811    /// assert_eq!(TextType::from_type_attr("text/html"), TextType::Html);
812    /// assert_eq!(TextType::from_type_attr("application/xhtml+xml"), TextType::Xhtml);
813    /// assert_eq!(TextType::from_type_attr("bogus"), TextType::Html);
814    /// ```
815    #[must_use]
816    pub fn from_type_attr(raw: &str) -> Self {
817        match raw.trim().to_ascii_lowercase().as_str() {
818            "text" | "text/plain" => Self::Text,
819            "xhtml" | "application/xhtml+xml" => Self::Xhtml,
820            _ => Self::Html,
821        }
822    }
823}
824
825/// Text construct with metadata
826#[derive(Debug, Clone)]
827#[non_exhaustive]
828pub struct TextConstruct {
829    /// Text content
830    pub value: String,
831    /// Content type
832    pub content_type: TextType,
833    /// Content language (stored inline for lang codes ≤24 bytes)
834    pub language: Option<SmallString>,
835    /// Base URL for relative links
836    pub base: Option<String>,
837}
838
839impl TextConstruct {
840    /// Create plain text construct
841    #[inline]
842    pub fn text(value: impl Into<String>) -> Self {
843        Self {
844            value: value.into(),
845            content_type: TextType::Text,
846            language: None,
847            base: None,
848        }
849    }
850
851    /// Create HTML text construct
852    #[inline]
853    pub fn html(value: impl Into<String>) -> Self {
854        Self {
855            value: value.into(),
856            content_type: TextType::Html,
857            language: None,
858            base: None,
859        }
860    }
861
862    /// Set language (builder pattern)
863    #[inline]
864    #[must_use]
865    pub fn with_language(mut self, language: impl AsRef<str>) -> Self {
866        self.language = Some(language.as_ref().into());
867        self
868    }
869}
870
871/// Generator metadata
872#[derive(Debug, Clone)]
873#[non_exhaustive]
874pub struct Generator {
875    /// Generator name (text content of the `<generator>` element)
876    pub name: String,
877    /// Generator URI (href attribute)
878    pub href: Option<String>,
879    /// Generator version (stored inline for versions ≤24 bytes)
880    pub version: Option<SmallString>,
881}
882
883impl Generator {
884    /// Creates a `Generator` from its required `name`; every other field is empty.
885    ///
886    /// # Examples
887    ///
888    /// ```
889    /// use feedparser_rs::Generator;
890    ///
891    /// let generator = Generator::new("Example Generator");
892    /// assert_eq!(generator.name, "Example Generator");
893    /// ```
894    #[must_use]
895    pub fn new(name: impl Into<String>) -> Self {
896        Self {
897            name: name.into(),
898            href: None,
899            version: None,
900        }
901    }
902}
903
904/// Source reference (for entries)
905#[derive(Debug, Clone, Default)]
906#[non_exhaustive]
907pub struct Source {
908    /// Source title
909    pub title: Option<String>,
910    /// Primary source URL for RSS `<source url="...">` (RSS-only field)
911    pub href: Option<String>,
912    /// Primary source URL for Atom `<source><link href="..."/>` (Atom-only field)
913    pub link: Option<String>,
914    /// Source author (flat string, Atom `<source><author>`)
915    pub author: Option<String>,
916    /// Source unique identifier
917    pub id: Option<String>,
918    /// All links from the source element
919    pub links: Vec<Link>,
920    /// Last update date (Atom `<updated>`)
921    pub updated: Option<Timestamp>,
922    /// Original update date string (timezone preserved)
923    pub updated_str: Option<String>,
924    /// Rights/copyright statement (Atom `<rights>`)
925    pub rights: Option<String>,
926    /// Whether `<id>` was used as the link.
927    ///
928    /// `Some(true)` when `<id>` looks like a URL and no explicit `<link>` was present.
929    /// `Some(false)` when `<id>` is present but a `<link>` was also present, or `<id>` is not a URL.
930    /// `None` for RSS sources (RSS `<source>` has no `<id>`).
931    pub guidislink: Option<bool>,
932}
933
934/// Media RSS thumbnail
935#[derive(Debug, Clone)]
936#[non_exhaustive]
937pub struct MediaThumbnail {
938    /// Thumbnail URL
939    ///
940    /// # Security Warning
941    ///
942    /// This URL comes from untrusted feed input and has NOT been validated for SSRF.
943    /// Applications MUST validate URLs before fetching to prevent SSRF attacks.
944    pub url: Url,
945    /// Thumbnail width in pixels (raw string value, as in Python feedparser)
946    pub width: Option<String>,
947    /// Thumbnail height in pixels (raw string value, as in Python feedparser)
948    pub height: Option<String>,
949    /// Time offset in NTP format (time attribute)
950    ///
951    /// Indicates which frame of the media this thumbnail represents.
952    pub time: Option<String>,
953}
954
955impl MediaThumbnail {
956    /// Creates a `MediaThumbnail` from its required `url`; every other field is empty.
957    ///
958    /// # Examples
959    ///
960    /// ```
961    /// use feedparser_rs::MediaThumbnail;
962    ///
963    /// let thumbnail = MediaThumbnail::new("https://example.com/t.jpg".into());
964    /// assert!(thumbnail.width.is_none());
965    /// ```
966    #[must_use]
967    pub const fn new(url: Url) -> Self {
968        Self {
969            url,
970            width: None,
971            height: None,
972            time: None,
973        }
974    }
975}
976
977/// Media RSS content
978#[derive(Debug, Clone)]
979#[non_exhaustive]
980pub struct MediaContent {
981    /// Media URL
982    ///
983    /// # Security Warning
984    ///
985    /// This URL comes from untrusted feed input and has NOT been validated for SSRF.
986    /// Applications MUST validate URLs before fetching to prevent SSRF attacks.
987    pub url: Url,
988    /// MIME type
989    pub content_type: Option<MimeType>,
990    /// Medium type: "image", "video", "audio", "document", "executable"
991    pub medium: Option<String>,
992    /// File size in bytes (raw string value, as in Python feedparser)
993    pub filesize: Option<String>,
994    /// Media width in pixels (raw string value, as in Python feedparser)
995    pub width: Option<String>,
996    /// Media height in pixels (raw string value, as in Python feedparser)
997    pub height: Option<String>,
998    /// Duration in seconds (raw string value, as in Python feedparser)
999    pub duration: Option<String>,
1000    /// Bitrate in kilobits per second (raw string value)
1001    pub bitrate: Option<String>,
1002    /// Language of the media (lang attribute)
1003    pub lang: Option<String>,
1004    /// Number of audio channels (raw string value)
1005    pub channels: Option<String>,
1006    /// Codec used to produce the media (codec attribute)
1007    pub codec: Option<String>,
1008    /// Expression type: "full", "sample", "nonstop"
1009    pub expression: Option<String>,
1010    /// Whether this is the default media object (isDefault attribute, raw string)
1011    pub isdefault: Option<String>,
1012    /// Sampling rate in kHz (raw string value)
1013    pub samplingrate: Option<String>,
1014    /// Frame rate in frames per second (raw string value)
1015    pub framerate: Option<String>,
1016}
1017
1018impl MediaContent {
1019    /// Creates a `MediaContent` from its required `url`; every other field is empty.
1020    ///
1021    /// # Examples
1022    ///
1023    /// ```
1024    /// use feedparser_rs::MediaContent;
1025    ///
1026    /// let content = MediaContent::new("https://example.com/v.mp4".into());
1027    /// assert!(content.medium.is_none());
1028    /// ```
1029    #[must_use]
1030    pub const fn new(url: Url) -> Self {
1031        Self {
1032            url,
1033            content_type: None,
1034            medium: None,
1035            filesize: None,
1036            width: None,
1037            height: None,
1038            duration: None,
1039            bitrate: None,
1040            lang: None,
1041            channels: None,
1042            codec: None,
1043            expression: None,
1044            isdefault: None,
1045            samplingrate: None,
1046            framerate: None,
1047        }
1048    }
1049}
1050
1051/// Media RSS rating element (`media:rating`)
1052///
1053/// Describes the permissible audience for the media content.
1054/// Commonly uses the MPAA or urn:simple rating schemes.
1055#[derive(Debug, Clone, Default, PartialEq, Eq)]
1056#[non_exhaustive]
1057pub struct MediaRating {
1058    /// Rating scheme URI (scheme attribute), e.g. "urn:simple", "urn:mpaa"
1059    pub scheme: Option<String>,
1060    /// Rating value, e.g. "adult", "nonadult", "pg-13"
1061    pub content: String,
1062}
1063
1064impl FromAttributes for Link {
1065    fn from_attributes<'a, I>(attrs: I, max_attr_length: usize) -> Option<Self>
1066    where
1067        I: Iterator<Item = quick_xml::events::attributes::Attribute<'a>>,
1068    {
1069        let mut href = None;
1070        let mut rel = None;
1071        let mut link_type = None;
1072        let mut title = None;
1073        let mut hreflang = None;
1074        let mut length = None;
1075        let mut thr_count = None;
1076        let mut thr_updated = None;
1077
1078        for attr in attrs {
1079            if attr.value.len() > max_attr_length {
1080                continue;
1081            }
1082            match attr.key.as_ref() {
1083                "href" => href = Some(attr.value.to_string()),
1084                "rel" => rel = Some(attr.value.to_string()),
1085                "type" => link_type = Some(attr.value.to_string()),
1086                "title" => title = Some(attr.value.to_string()),
1087                "hreflang" => hreflang = Some(attr.value.to_string()),
1088                "length" => length = Some(attr.value.to_string()),
1089                "thr:count" => {
1090                    thr_count = attr.value.to_string().trim().parse::<u32>().ok();
1091                }
1092                "thr:updated" => {
1093                    thr_updated = parse_date(attr.value.to_string().trim());
1094                }
1095                _ => {}
1096            }
1097        }
1098
1099        let rel_str: Option<SmallString> = rel
1100            .map(std::convert::Into::into)
1101            .or_else(|| Some("alternate".into()));
1102        let resolved_type = link_type
1103            .map(MimeType::new)
1104            .or_else(|| match rel_str.as_deref() {
1105                Some("self") => Some(MimeType::new("application/atom+xml")),
1106                _ => Some(MimeType::new("text/html")),
1107            });
1108
1109        href.map(|href| Self {
1110            href: Url::new(href),
1111            rel: rel_str,
1112            link_type: resolved_type,
1113            title,
1114            length,
1115            hreflang: hreflang.map(std::convert::Into::into),
1116            thr_count,
1117            thr_updated,
1118            ..Self::default()
1119        })
1120    }
1121}
1122
1123impl FromAttributes for Tag {
1124    fn from_attributes<'a, I>(attrs: I, max_attr_length: usize) -> Option<Self>
1125    where
1126        I: Iterator<Item = quick_xml::events::attributes::Attribute<'a>>,
1127    {
1128        let mut term = None;
1129        let mut scheme = None;
1130        let mut label = None;
1131
1132        for attr in attrs {
1133            if attr.value.len() > max_attr_length {
1134                continue;
1135            }
1136
1137            match attr.key.as_ref() {
1138                "term" => term = Some(attr.value.to_string()),
1139                "scheme" | "domain" => scheme = Some(attr.value.to_string()),
1140                "label" => label = Some(attr.value.to_string()),
1141                _ => {}
1142            }
1143        }
1144
1145        term.map(|term| Self {
1146            term: term.into(),
1147            scheme: scheme.map(std::convert::Into::into),
1148            label: label.map(std::convert::Into::into),
1149        })
1150    }
1151}
1152
1153impl FromAttributes for Enclosure {
1154    fn from_attributes<'a, I>(attrs: I, max_attr_length: usize) -> Option<Self>
1155    where
1156        I: Iterator<Item = quick_xml::events::attributes::Attribute<'a>>,
1157    {
1158        let mut url = None;
1159        let mut length = None;
1160        let mut enclosure_type = None;
1161
1162        for attr in attrs {
1163            if attr.value.len() > max_attr_length {
1164                continue;
1165            }
1166
1167            match attr.key.as_ref() {
1168                "url" => url = Some(attr.value.to_string()),
1169                "length" => length = Some(attr.value.to_string()),
1170                "type" => enclosure_type = Some(attr.value.to_string()),
1171                _ => {}
1172            }
1173        }
1174
1175        url.map(|url| Self {
1176            url: Url::new(url),
1177            length,
1178            enclosure_type: enclosure_type.map(MimeType::new),
1179            title: None,
1180            duration: None,
1181            ..Self::default()
1182        })
1183    }
1184}
1185
1186impl FromAttributes for MediaThumbnail {
1187    fn from_attributes<'a, I>(attrs: I, max_attr_length: usize) -> Option<Self>
1188    where
1189        I: Iterator<Item = quick_xml::events::attributes::Attribute<'a>>,
1190    {
1191        let mut url = None;
1192        let mut width = None;
1193        let mut height = None;
1194
1195        let mut time = None;
1196
1197        for attr in attrs {
1198            if attr.value.len() > max_attr_length {
1199                continue;
1200            }
1201
1202            match attr.key.as_ref() {
1203                "url" => url = Some(attr.value.to_string()),
1204                "width" => width = Some(attr.value.to_string()),
1205                "height" => height = Some(attr.value.to_string()),
1206                "time" => time = Some(attr.value.to_string()),
1207                _ => {}
1208            }
1209        }
1210
1211        url.map(|url| Self {
1212            url: Url::new(url),
1213            width,
1214            height,
1215            time,
1216        })
1217    }
1218}
1219
1220impl FromAttributes for MediaContent {
1221    fn from_attributes<'a, I>(attrs: I, max_attr_length: usize) -> Option<Self>
1222    where
1223        I: Iterator<Item = quick_xml::events::attributes::Attribute<'a>>,
1224    {
1225        let mut url = None;
1226        let mut content_type = None;
1227        let mut medium = None;
1228        let mut filesize = None;
1229        let mut width = None;
1230        let mut height = None;
1231        let mut duration = None;
1232        let mut bitrate = None;
1233        let mut lang = None;
1234        let mut channels = None;
1235        let mut codec = None;
1236        let mut expression = None;
1237        let mut isdefault = None;
1238        let mut samplingrate = None;
1239        let mut framerate = None;
1240
1241        for attr in attrs {
1242            if attr.value.len() > max_attr_length {
1243                continue;
1244            }
1245
1246            match attr.key.as_ref() {
1247                "url" => url = Some(attr.value.to_string()),
1248                "type" => content_type = Some(attr.value.to_string()),
1249                "medium" => medium = Some(attr.value.to_string()),
1250                "fileSize" => filesize = Some(attr.value.to_string()),
1251                "width" => width = Some(attr.value.to_string()),
1252                "height" => height = Some(attr.value.to_string()),
1253                "duration" => duration = Some(attr.value.to_string()),
1254                "bitrate" => bitrate = Some(attr.value.to_string()),
1255                "lang" => lang = Some(attr.value.to_string()),
1256                "channels" => channels = Some(attr.value.to_string()),
1257                "codec" => codec = Some(attr.value.to_string()),
1258                "expression" => expression = Some(attr.value.to_string()),
1259                "isDefault" => isdefault = Some(attr.value.to_string()),
1260                "samplingrate" => samplingrate = Some(attr.value.to_string()),
1261                "framerate" => framerate = Some(attr.value.to_string()),
1262                _ => {}
1263            }
1264        }
1265
1266        url.map(|url| Self {
1267            url: Url::new(url),
1268            content_type: content_type.map(MimeType::new),
1269            medium,
1270            filesize,
1271            width,
1272            height,
1273            duration,
1274            bitrate,
1275            lang,
1276            channels,
1277            codec,
1278            expression,
1279            isdefault,
1280            samplingrate,
1281            framerate,
1282        })
1283    }
1284}
1285
1286// ParseFrom implementations for JSON Feed parsing
1287
1288impl ParseFrom<&Value> for Person {
1289    /// Parse Person from JSON Feed author object
1290    ///
1291    /// JSON Feed format: `{"name": "...", "url": "...", "avatar": "..."}`
1292    fn parse_from(json: &Value) -> Option<Self> {
1293        json.as_object().map(|obj| Self {
1294            name: obj
1295                .get("name")
1296                .and_then(Value::as_str)
1297                .map(std::convert::Into::into),
1298            email: None, // JSON Feed doesn't have email field
1299            uri: obj.get("url").and_then(Value::as_str).map(String::from),
1300            avatar: obj.get("avatar").and_then(Value::as_str).map(String::from),
1301            ..Self::default()
1302        })
1303    }
1304}
1305
1306impl ParseFrom<&Value> for Enclosure {
1307    /// Parse Enclosure from JSON Feed attachment object
1308    ///
1309    /// JSON Feed format: `{"url": "...", "mime_type": "...", "size_in_bytes": ...}`
1310    fn parse_from(json: &Value) -> Option<Self> {
1311        let obj = json.as_object()?;
1312        let url = obj.get("url").and_then(Value::as_str)?;
1313        Some(Self {
1314            url: Url::new(url),
1315            length: obj
1316                .get("size_in_bytes")
1317                .and_then(Value::as_u64)
1318                .map(|v| v.to_string()),
1319            enclosure_type: obj
1320                .get("mime_type")
1321                .and_then(Value::as_str)
1322                .map(MimeType::new),
1323            title: obj.get("title").and_then(Value::as_str).map(String::from),
1324            duration: obj
1325                .get("duration_in_seconds")
1326                .and_then(Value::as_u64)
1327                .map(|v| v.to_string()),
1328            ..Self::default()
1329        })
1330    }
1331}
1332
1333/// Media RSS credit element (media:credit)
1334#[derive(Debug, Clone, Default)]
1335#[non_exhaustive]
1336pub struct MediaCredit {
1337    /// Credit role (e.g., "author", "producer")
1338    pub role: Option<String>,
1339    /// Credit scheme URI (default: "urn:ebu")
1340    pub scheme: Option<String>,
1341    /// Credit text content (person/entity name)
1342    pub content: String,
1343}
1344
1345/// Media RSS copyright element (media:copyright)
1346#[derive(Debug, Clone, Default)]
1347#[non_exhaustive]
1348pub struct MediaCopyright {
1349    /// Copyright URL
1350    pub url: Option<String>,
1351}
1352
1353#[cfg(test)]
1354mod tests {
1355    use super::*;
1356    use serde_json::json;
1357
1358    #[test]
1359    fn test_link_default() {
1360        let link = Link::default();
1361        assert!(link.href.is_empty());
1362        assert!(link.rel.is_none());
1363    }
1364
1365    #[test]
1366    fn test_link_builders() {
1367        let link = Link::alternate("https://example.com");
1368        assert_eq!(link.href, "https://example.com");
1369        assert_eq!(link.rel.as_deref(), Some("alternate"));
1370
1371        let link = Link::self_link("https://example.com/feed", "application/feed+json");
1372        assert_eq!(link.rel.as_deref(), Some("self"));
1373        assert_eq!(link.link_type.as_deref(), Some("application/feed+json"));
1374
1375        let link = Link::enclosure("https://example.com/audio.mp3", Some("audio/mpeg".into()));
1376        assert_eq!(link.rel.as_deref(), Some("enclosure"));
1377        assert_eq!(link.link_type.as_deref(), Some("audio/mpeg"));
1378
1379        let link = Link::related("https://other.com");
1380        assert_eq!(link.rel.as_deref(), Some("related"));
1381    }
1382
1383    #[test]
1384    fn test_tag_builder() {
1385        let tag = Tag::new("rust");
1386        assert_eq!(tag.term, "rust");
1387        assert!(tag.scheme.is_none());
1388    }
1389
1390    #[test]
1391    fn test_text_construct_builders() {
1392        let text = TextConstruct::text("Hello");
1393        assert_eq!(text.value, "Hello");
1394        assert_eq!(text.content_type, TextType::Text);
1395
1396        let html = TextConstruct::html("<p>Hello</p>");
1397        assert_eq!(html.content_type, TextType::Html);
1398
1399        let with_lang = TextConstruct::text("Hello").with_language("en");
1400        assert_eq!(with_lang.language.as_deref(), Some("en"));
1401    }
1402
1403    #[test]
1404    fn test_content_builders() {
1405        let html = Content::html("<p>Content</p>");
1406        assert_eq!(html.content_type.as_deref(), Some("text/html"));
1407
1408        let plain = Content::plain("Content");
1409        assert_eq!(plain.content_type.as_deref(), Some("text/plain"));
1410    }
1411
1412    #[test]
1413    fn test_person_default() {
1414        let person = Person::default();
1415        assert!(person.name.is_none());
1416        assert!(person.email.is_none());
1417        assert!(person.uri.is_none());
1418    }
1419
1420    #[test]
1421    fn test_person_parse_from_json() {
1422        let json = json!({"name": "John Doe", "url": "https://example.com"});
1423        let person = Person::parse_from(&json).unwrap();
1424        assert_eq!(person.name.as_deref(), Some("John Doe"));
1425        assert_eq!(person.uri.as_deref(), Some("https://example.com"));
1426        assert!(person.email.is_none());
1427    }
1428
1429    #[test]
1430    fn test_person_parse_from_empty_json() {
1431        let json = json!({});
1432        let person = Person::parse_from(&json).unwrap();
1433        assert!(person.name.is_none());
1434    }
1435
1436    #[test]
1437    fn test_enclosure_parse_from_json() {
1438        let json = json!({
1439            "url": "https://example.com/file.mp3",
1440            "mime_type": "audio/mpeg",
1441            "size_in_bytes": 12345
1442        });
1443        let enclosure = Enclosure::parse_from(&json).unwrap();
1444        assert_eq!(enclosure.url, "https://example.com/file.mp3");
1445        assert_eq!(enclosure.enclosure_type.as_deref(), Some("audio/mpeg"));
1446        assert_eq!(enclosure.length.as_deref(), Some("12345"));
1447    }
1448
1449    #[test]
1450    fn test_enclosure_parse_from_json_missing_url() {
1451        let json = json!({"mime_type": "audio/mpeg"});
1452        assert!(Enclosure::parse_from(&json).is_none());
1453    }
1454
1455    #[test]
1456    fn test_text_type_equality() {
1457        assert_eq!(TextType::Text, TextType::Text);
1458        assert_ne!(TextType::Text, TextType::Html);
1459    }
1460
1461    // Newtype tests
1462
1463    #[test]
1464    fn test_url_new() {
1465        let url = Url::new("https://example.com");
1466        assert_eq!(url.as_str(), "https://example.com");
1467    }
1468
1469    #[test]
1470    fn test_url_from_string() {
1471        let url: Url = String::from("https://example.com").into();
1472        assert_eq!(url.as_str(), "https://example.com");
1473    }
1474
1475    #[test]
1476    fn test_url_from_str() {
1477        let url: Url = "https://example.com".into();
1478        assert_eq!(url.as_str(), "https://example.com");
1479    }
1480
1481    #[test]
1482    fn test_url_deref() {
1483        let url = Url::new("https://example.com");
1484        // Deref allows calling str methods directly
1485        assert_eq!(url.len(), 19);
1486        assert!(url.starts_with("https://"));
1487    }
1488
1489    #[test]
1490    fn test_url_into_inner() {
1491        let url = Url::new("https://example.com");
1492        let inner = url.into_inner();
1493        assert_eq!(inner, "https://example.com");
1494    }
1495
1496    #[test]
1497    fn test_url_default() {
1498        let url = Url::default();
1499        assert_eq!(url.as_str(), "");
1500    }
1501
1502    #[test]
1503    fn test_url_clone() {
1504        let url1 = Url::new("https://example.com");
1505        let url2 = url1.clone();
1506        assert_eq!(url1, url2);
1507    }
1508
1509    #[test]
1510    fn test_mime_type_new() {
1511        let mime = MimeType::new("text/html");
1512        assert_eq!(mime.as_str(), "text/html");
1513    }
1514
1515    #[test]
1516    fn test_mime_type_from_string() {
1517        let mime: MimeType = String::from("application/json").into();
1518        assert_eq!(mime.as_str(), "application/json");
1519    }
1520
1521    #[test]
1522    fn test_mime_type_from_str() {
1523        let mime: MimeType = "text/plain".into();
1524        assert_eq!(mime.as_str(), "text/plain");
1525    }
1526
1527    #[test]
1528    fn test_mime_type_deref() {
1529        let mime = MimeType::new("text/html");
1530        assert_eq!(mime.len(), 9);
1531        assert!(mime.starts_with("text/"));
1532    }
1533
1534    #[test]
1535    fn test_mime_type_default() {
1536        let mime = MimeType::default();
1537        assert_eq!(mime.as_str(), "");
1538    }
1539
1540    #[test]
1541    fn test_mime_type_clone() {
1542        let mime1 = MimeType::new("application/xml");
1543        let mime2 = mime1.clone();
1544        assert_eq!(mime1, mime2);
1545        // Arc cloning is cheap - just increments refcount
1546    }
1547
1548    #[test]
1549    fn test_mime_type_constants() {
1550        assert_eq!(MimeType::TEXT_HTML, "text/html");
1551        assert_eq!(MimeType::TEXT_PLAIN, "text/plain");
1552        assert_eq!(MimeType::APPLICATION_XML, "application/xml");
1553        assert_eq!(MimeType::APPLICATION_JSON, "application/json");
1554    }
1555
1556    #[test]
1557    fn test_email_new() {
1558        let email = Email::new("user@example.com");
1559        assert_eq!(email.as_str(), "user@example.com");
1560    }
1561
1562    #[test]
1563    fn test_email_from_string() {
1564        let email: Email = String::from("user@example.com").into();
1565        assert_eq!(email.as_str(), "user@example.com");
1566    }
1567
1568    #[test]
1569    fn test_email_from_str() {
1570        let email: Email = "user@example.com".into();
1571        assert_eq!(email.as_str(), "user@example.com");
1572    }
1573
1574    #[test]
1575    fn test_email_deref() {
1576        let email = Email::new("user@example.com");
1577        assert_eq!(email.len(), 16);
1578        assert!(email.contains('@'));
1579    }
1580
1581    #[test]
1582    fn test_email_into_inner() {
1583        let email = Email::new("user@example.com");
1584        let inner = email.into_inner();
1585        assert_eq!(inner, "user@example.com");
1586    }
1587
1588    #[test]
1589    fn test_email_default() {
1590        let email = Email::default();
1591        assert_eq!(email.as_str(), "");
1592    }
1593
1594    #[test]
1595    fn test_email_clone() {
1596        let email1 = Email::new("user@example.com");
1597        let email2 = email1.clone();
1598        assert_eq!(email1, email2);
1599    }
1600}