Add helpers

This commit is contained in:
Dominik Werder
2025-03-13 10:31:19 +01:00
parent 302bc811fd
commit 360faea1ae
3 changed files with 21 additions and 1 deletions

View File

@@ -4523,7 +4523,11 @@ pub fn req_uri_to_url(uri: &Uri) -> Result<Url, UriError> {
}
}
pub unsafe fn extltref<'a, 'b, T>(t: &'a T) -> &'b T {
pub unsafe fn extltref<'a, 'b, T>(x: &'a T) -> &'b T {
&*(x as *const T)
}
pub unsafe fn extltref2<'a, 'b, T>(t: &'a T) -> &'b T {
core::mem::transmute(t)
}

View File

@@ -198,6 +198,13 @@ impl SeriesRange {
SeriesRange::PulseRange(x) => x.end - x.beg,
}
}
pub fn to_time(&self) -> Option<NanoRange> {
match self {
SeriesRange::TimeRange(x) => Some(x.clone()),
SeriesRange::PulseRange(_) => None,
}
}
}
impl fmt::Debug for SeriesRange {

View File

@@ -74,6 +74,15 @@ impl RetentionTime {
RetentionTime::Long => 12,
}
}
pub fn from_str(x: &str) -> Result<Self, Error> {
match x {
"short" => Ok(Self::Short),
"medium" => Ok(Self::Medium),
"long" => Ok(Self::Long),
_ => Err(Error::Parse),
}
}
}
impl fmt::Display for RetentionTime {