pub struct Timestamp(/* private fields */);Expand description
An RFC 3339 / ISO 8601 timestamp as returned by the Ticksupply API.
Holds the server-supplied string losslessly; typed access is available
via Self::to_chrono and Self::to_time under their respective
Cargo features. Parse errors surface only when a typed accessor is
called, so deserialization never fails on an unexpected timestamp
format — you still get the raw string via Self::as_str.
§Examples
use ticksupply::Timestamp;
let t = Timestamp::from("2024-01-01T00:00:00Z");
assert_eq!(t.as_str(), "2024-01-01T00:00:00Z");Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the raw RFC 3339 / ISO 8601 string.
§Examples
use ticksupply::Timestamp;
assert_eq!(Timestamp::from("2024-01-01T00:00:00Z").as_str(), "2024-01-01T00:00:00Z");Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Sourcepub fn to_chrono(&self) -> Result<DateTime<Utc>, ParseError>
Available on crate feature chrono only.
pub fn to_chrono(&self) -> Result<DateTime<Utc>, ParseError>
chrono only.Parses the wire string as a chrono::DateTime<Utc>.
Available when the chrono feature is enabled (default). The result
is normalized to UTC; a timestamp with a non-UTC offset is converted
in-place.
§Errors
Returns chrono::ParseError if the wire string is not a valid
RFC 3339 timestamp.
§Examples
use ticksupply::Timestamp;
let t = Timestamp::from("2024-01-01T00:00:00Z");
let dt = t.to_chrono().unwrap();
assert_eq!(dt.to_rfc3339(), "2024-01-01T00:00:00+00:00");Sourcepub fn to_time(&self) -> Result<OffsetDateTime, Parse>
Available on crate feature time only.
pub fn to_time(&self) -> Result<OffsetDateTime, Parse>
time only.Parses the wire string as a time::OffsetDateTime.
Available when the time feature is enabled.
§Errors
Returns time::error::Parse if the wire string is not a valid
RFC 3339 timestamp.
§Examples
use ticksupply::Timestamp;
let t = Timestamp::from("2024-01-01T00:00:00Z");
let dt = t.to_time().unwrap();
assert_eq!(dt.unix_timestamp(), 1_704_067_200);Trait Implementations§
Source§impl<'de> Deserialize<'de> for Timestamp
impl<'de> Deserialize<'de> for Timestamp
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Timestamp
impl StructuralPartialEq for Timestamp
Auto Trait Implementations§
impl Freeze for Timestamp
impl RefUnwindSafe for Timestamp
impl Send for Timestamp
impl Sync for Timestamp
impl Unpin for Timestamp
impl UnsafeUnpin for Timestamp
impl UnwindSafe for Timestamp
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.