Skip to main content

user_agent_parser/models/
os.rs

1use std::borrow::Cow;
2
3/// The operating system a user agent runs on.
4#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
5pub struct OS<'a> {
6    /// The OS family, which falls back to `Some("Other")` when no pattern matches.
7    pub name:        Option<Cow<'a, str>>,
8    /// The major version, if the matching pattern captures one.
9    pub major:       Option<Cow<'a, str>>,
10    /// The minor version, if the matching pattern captures one.
11    pub minor:       Option<Cow<'a, str>>,
12    /// The patch version, if the matching pattern captures one.
13    pub patch:       Option<Cow<'a, str>>,
14    /// The patch minor version, if the matching pattern captures one.
15    pub patch_minor: Option<Cow<'a, str>>,
16}
17
18impl<'a> OS<'a> {
19    /// Extracts the owned data.
20    #[inline]
21    pub fn into_owned(self) -> OS<'static> {
22        let name = self.name.map(|c| Cow::from(c.into_owned()));
23        let major = self.major.map(|c| Cow::from(c.into_owned()));
24        let minor = self.minor.map(|c| Cow::from(c.into_owned()));
25        let patch = self.patch.map(|c| Cow::from(c.into_owned()));
26        let patch_minor = self.patch_minor.map(|c| Cow::from(c.into_owned()));
27
28        OS {
29            name,
30            major,
31            minor,
32            patch,
33            patch_minor,
34        }
35    }
36}