From 360faea1aea72b0bc8d6aea22d65ba896bbd9d08 Mon Sep 17 00:00:00 2001 From: Dominik Werder Date: Thu, 13 Mar 2025 10:31:19 +0100 Subject: [PATCH] Add helpers --- src/netpod.rs | 6 +++++- src/range/evrange.rs | 7 +++++++ src/ttl.rs | 9 +++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/netpod.rs b/src/netpod.rs index 7017bac..0b985f4 100644 --- a/src/netpod.rs +++ b/src/netpod.rs @@ -4523,7 +4523,11 @@ pub fn req_uri_to_url(uri: &Uri) -> Result { } } -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) } diff --git a/src/range/evrange.rs b/src/range/evrange.rs index 518e4f7..93d7f83 100644 --- a/src/range/evrange.rs +++ b/src/range/evrange.rs @@ -198,6 +198,13 @@ impl SeriesRange { SeriesRange::PulseRange(x) => x.end - x.beg, } } + + pub fn to_time(&self) -> Option { + match self { + SeriesRange::TimeRange(x) => Some(x.clone()), + SeriesRange::PulseRange(_) => None, + } + } } impl fmt::Debug for SeriesRange { diff --git a/src/ttl.rs b/src/ttl.rs index 61710cf..a564e19 100644 --- a/src/ttl.rs +++ b/src/ttl.rs @@ -74,6 +74,15 @@ impl RetentionTime { RetentionTime::Long => 12, } } + + pub fn from_str(x: &str) -> Result { + match x { + "short" => Ok(Self::Short), + "medium" => Ok(Self::Medium), + "long" => Ok(Self::Long), + _ => Err(Error::Parse), + } + } } impl fmt::Display for RetentionTime {