librespot/metadata/src/sale_period.rs

43 lines
1 KiB
Rust
Raw Normal View History

2022-01-14 22:42:18 +00:00
use std::{
convert::{TryFrom, TryInto},
fmt::Debug,
ops::Deref,
};
2022-01-14 22:28:09 +00:00
use crate::{restriction::Restrictions, util::try_from_repeated_message};
2021-12-16 21:42:37 +00:00
use librespot_core::date::Date;
use librespot_protocol as protocol;
use protocol::metadata::SalePeriod as SalePeriodMessage;
#[derive(Debug, Clone)]
pub struct SalePeriod {
pub restrictions: Restrictions,
pub start: Date,
pub end: Date,
}
#[derive(Debug, Clone, Default)]
pub struct SalePeriods(pub Vec<SalePeriod>);
impl Deref for SalePeriods {
type Target = Vec<SalePeriod>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
2022-01-14 22:28:09 +00:00
impl TryFrom<&SalePeriodMessage> for SalePeriod {
type Error = librespot_core::Error;
fn try_from(sale_period: &SalePeriodMessage) -> Result<Self, Self::Error> {
Ok(Self {
restrictions: sale_period.get_restriction().into(),
2022-01-14 22:28:09 +00:00
start: sale_period.get_start().try_into()?,
end: sale_period.get_end().try_into()?,
})
}
}
2022-01-14 22:28:09 +00:00
try_from_repeated_message!(SalePeriodMessage, SalePeriods);