use std::str::FromStr;
use crate::{Error, Time};
use smallvec::SmallVec;
#[derive(Default, Clone)]
pub struct TimeBuf {
buf: SmallVec<[u8; Time::MAX.size()]>,
}
impl TimeBuf {
pub fn as_str(&self) -> &str {
let time_bytes = self.buf.as_slice();
std::str::from_utf8(time_bytes).expect("time serializes as valid UTF-8")
}
fn clear(&mut self) {
self.buf.clear();
}
}
impl Time {
pub fn to_str<'a>(&self, buf: &'a mut TimeBuf) -> &'a str {
buf.clear();
self.write_to(&mut buf.buf)
.expect("write to memory of just the right size cannot fail");
buf.as_str()
}
}
impl FromStr for Time {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
crate::parse_header(s).ok_or_else(|| Error::new_with_input("invalid time", s))
}
}
pub(crate) mod function;
mod git;
mod raw;
mod relative;