Skip to main content

user_agent_parser/models/
engine.rs

1use std::borrow::Cow;
2
3/// The layout engine of the product a user agent belongs to.
4#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
5pub struct Engine<'a> {
6    /// The engine name, or `None` 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}
15
16impl<'a> Engine<'a> {
17    /// Extracts the owned data.
18    #[inline]
19    pub fn into_owned(self) -> Engine<'static> {
20        let name = self.name.map(|c| Cow::from(c.into_owned()));
21        let major = self.major.map(|c| Cow::from(c.into_owned()));
22        let minor = self.minor.map(|c| Cow::from(c.into_owned()));
23        let patch = self.patch.map(|c| Cow::from(c.into_owned()));
24
25        Engine {
26            name,
27            major,
28            minor,
29            patch,
30        }
31    }
32}