pub struct Timestamp { /* private fields */ }
Expand description
A newtype wrapper over Option<Time>
to keep track of
IBC packet timeout.
We use an explicit Option
type to distinguish this when converting between
a u64
value and a raw timestamp. In protocol buffer, the timestamp is
represented as a u64
Unix timestamp in nanoseconds, with 0 representing the absence
of timestamp.
Implementations
sourceimpl Timestamp
impl Timestamp
sourcepub fn from_nanoseconds(
nanoseconds: u64
) -> Result<Timestamp, ParseTimestampError>
pub fn from_nanoseconds(
nanoseconds: u64
) -> Result<Timestamp, ParseTimestampError>
The IBC protocol represents timestamps as u64 Unix timestamps in nanoseconds.
A protocol value of 0 indicates that the timestamp is not set. In this case, our domain type takes the value of None.
sourcepub fn duration_since(&self, other: &Timestamp) -> Option<Duration>
pub fn duration_since(&self, other: &Timestamp) -> Option<Duration>
Computes the duration difference of another Timestamp
from the current one.
Returns the difference in time as an core::time::Duration
.
Returns None
if the other Timestamp
is more advanced
than the current or if either of the Timestamp
s is not set.
sourcepub fn as_nanoseconds(&self) -> u64
👎Deprecated since 0.9.1: use nanoseconds
instead
pub fn as_nanoseconds(&self) -> u64
use nanoseconds
instead
Convert a Timestamp
to u64
value in nanoseconds. If no timestamp
is set, the result is 0.
sourcepub fn nanoseconds(self) -> u64
pub fn nanoseconds(self) -> u64
Convert a Timestamp
to u64
value in nanoseconds. If no timestamp
is set, the result is 0.
use ibc::timestamp::Timestamp;
let max = u64::MAX;
let tx = Timestamp::from_nanoseconds(max).unwrap();
let utx = tx.nanoseconds();
assert_eq!(utx, max);
let min = u64::MIN;
let ti = Timestamp::from_nanoseconds(min).unwrap();
let uti = ti.nanoseconds();
assert_eq!(uti, min);
let tz = Timestamp::default();
let utz = tz.nanoseconds();
assert_eq!(utz, 0);
sourcepub fn into_datetime(self) -> Option<OffsetDateTime>
pub fn into_datetime(self) -> Option<OffsetDateTime>
Convert a Timestamp
to an optional OffsetDateTime
sourcepub fn into_tm_time(self) -> Option<Time>
pub fn into_tm_time(self) -> Option<Time>
Convert a Timestamp
to an optional tendermint::Time
sourcepub fn check_expiry(&self, other: &Timestamp) -> Expiry
pub fn check_expiry(&self, other: &Timestamp) -> Expiry
Checks whether the timestamp has expired when compared to the
other
timestamp. Returns an Expiry
result.
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Timestamp
impl<'de> Deserialize<'de> for Timestamp
sourcefn 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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl PartialEq<Timestamp> for Timestamp
impl PartialEq<Timestamp> for Timestamp
impl Copy for Timestamp
impl Eq for Timestamp
impl StructuralEq for Timestamp
impl StructuralPartialEq for Timestamp
Auto Trait Implementations
impl RefUnwindSafe for Timestamp
impl Send for Timestamp
impl Sync for Timestamp
impl Unpin for Timestamp
impl UnwindSafe for Timestamp
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more