39 lines
965 B
Rust
39 lines
965 B
Rust
use super::BasicDate;
|
|
use serde::ser::{Serialize, SerializeStruct, Serializer};
|
|
|
|
/// Represents a date when a pickup will occur. Label describes which type of
|
|
/// trash will be picked up.
|
|
pub struct PickupTime {
|
|
date: BasicDate,
|
|
label: String,
|
|
}
|
|
|
|
impl PickupTime {
|
|
/// Creates a new PickupTime instance.
|
|
///
|
|
/// # Arguments
|
|
///
|
|
/// * `date` - Date of pickup time
|
|
/// * `label` - Type of trash
|
|
pub fn new(date: BasicDate, label: String) -> PickupTime {
|
|
PickupTime {
|
|
date: date,
|
|
label: label,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Serialize for PickupTime {
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
where
|
|
S: Serializer,
|
|
{
|
|
let mut s = serializer.serialize_struct("PickupTime", 2)?;
|
|
s.serialize_field("date", &self.date)?;
|
|
s.serialize_field("label", &self.label)?;
|
|
s.end()
|
|
}
|
|
}
|
|
|
|
// I'd put tests here, but there's barely anything to do
|