Skip to main content

user_agent_parser/models/
device.rs

1use std::borrow::Cow;
2
3/// The physical device a user agent runs on.
4#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
5pub struct Device<'a> {
6    /// The device family, which falls back to `Some("Other")` when no pattern matches.
7    pub name:  Option<Cow<'a, str>>,
8    /// The manufacturer, which is only set when the matching pattern names one.
9    pub brand: Option<Cow<'a, str>>,
10    /// The model, if the matching pattern captures one.
11    pub model: Option<Cow<'a, str>>,
12}
13
14impl<'a> Device<'a> {
15    /// Extracts the owned data.
16    #[inline]
17    pub fn into_owned(self) -> Device<'static> {
18        let name = self.name.map(|c| Cow::from(c.into_owned()));
19        let brand = self.brand.map(|c| Cow::from(c.into_owned()));
20        let model = self.model.map(|c| Cow::from(c.into_owned()));
21
22        Device {
23            name,
24            brand,
25            model,
26        }
27    }
28}