Struct ibc_primitives::Timestamp
source · pub struct Timestamp { /* private fields */ }
Expand description
A new type 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§
source§impl Timestamp
impl Timestamp
sourcepub fn from_nanoseconds(nanoseconds: u64) -> Result<Self, ParseTimestampError>
pub fn from_nanoseconds(nanoseconds: u64) -> Result<Self, 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: &Self) -> Option<Duration>
pub fn duration_since(&self, other: &Self) -> 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
nanoseconds
insteadConvert 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_primitives::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::none();
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: &Self) -> Expiry
pub fn check_expiry(&self, other: &Self) -> Expiry
Checks whether the timestamp has expired when compared to the
other
timestamp. Returns an Expiry
result.
Trait Implementations§
source§impl BorshDeserialize for Timestamp
impl BorshDeserialize for Timestamp
fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self>
source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
source§impl BorshSerialize for Timestamp
impl BorshSerialize for Timestamp
source§impl Decode for Timestamp
impl Decode for Timestamp
source§fn decode<I: Input>(input: &mut I) -> Result<Self, Error>
fn decode<I: Input>(input: &mut I) -> Result<Self, Error>
source§fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>
) -> Result<DecodeFinished, Error>where
I: Input,
fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>
) -> Result<DecodeFinished, Error>where
I: Input,
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>,
source§impl Encode for Timestamp
impl Encode for Timestamp
source§fn encode_to<T: Output + ?Sized>(&self, writer: &mut T)
fn encode_to<T: Output + ?Sized>(&self, writer: &mut T)
source§fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
source§fn using_encoded<R, F>(&self, f: F) -> R
fn using_encoded<R, F>(&self, f: F) -> R
source§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
source§impl JsonSchema for Timestamp
impl JsonSchema for Timestamp
source§fn schema_name() -> String
fn schema_name() -> String
source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moresource§impl Ord for Timestamp
impl Ord for Timestamp
source§impl PartialEq for Timestamp
impl PartialEq for Timestamp
source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more