use std::borrow::Cow;
use super::version::join_version;
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
pub struct Product<'a> {
pub name: Option<Cow<'a, str>>,
pub major: Option<Cow<'a, str>>,
pub minor: Option<Cow<'a, str>>,
pub patch: Option<Cow<'a, str>>,
pub patch_minor: Option<Cow<'a, str>>,
}
impl<'a> Product<'a> {
#[inline]
pub fn version(&self) -> Option<Cow<'_, str>> {
join_version(&[
self.major.as_deref(),
self.minor.as_deref(),
self.patch.as_deref(),
self.patch_minor.as_deref(),
])
}
#[inline]
pub fn into_owned(self) -> Product<'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()));
let patch_minor = self.patch_minor.map(|c| Cow::from(c.into_owned()));
Product {
name,
major,
minor,
patch,
patch_minor,
}
}
}