user-agent-parser 0.4.0

A parser to get the product, OS, device, cpu, and engine information from a user agent, inspired by https://github.com/faisalman/ua-parser-js and https://github.com/ua-parser/uap-core
Documentation
use std::borrow::Cow;

/// The layout engine of the product a user agent belongs to.
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
pub struct Engine<'a> {
    /// The engine name, or `None` when no pattern matches.
    pub name:  Option<Cow<'a, str>>,
    /// The major version, if the matching pattern captures one.
    pub major: Option<Cow<'a, str>>,
    /// The minor version, if the matching pattern captures one.
    pub minor: Option<Cow<'a, str>>,
    /// The patch version, if the matching pattern captures one.
    pub patch: Option<Cow<'a, str>>,
}

impl<'a> Engine<'a> {
    /// Extracts the owned data.
    #[inline]
    pub fn into_owned(self) -> Engine<'static> {
        let name = self.name.map(|c| Cow::from(c.into_owned()));
        let major = self.major.map(|c| Cow::from(c.into_owned()));
        let minor = self.minor.map(|c| Cow::from(c.into_owned()));
        let patch = self.patch.map(|c| Cow::from(c.into_owned()));

        Engine {
            name,
            major,
            minor,
            patch,
        }
    }
}