Struct ibc_core::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<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
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::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§
source§impl BorshDeserialize for Timestamp
impl BorshDeserialize for Timestamp
fn deserialize_reader<R>(reader: &mut R) -> Result<Timestamp, Error>where
R: Read,
§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
§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 Decode for Timestamp
impl Decode for Timestamp
source§fn decode<I>(input: &mut I) -> Result<Timestamp, Error>where
I: Input,
fn decode<I>(input: &mut I) -> Result<Timestamp, Error>where
I: Input,
§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,
§fn skip<I>(input: &mut I) -> Result<(), Error>where
I: Input,
fn skip<I>(input: &mut I) -> Result<(), Error>where
I: Input,
§fn encoded_fixed_size() -> Option<usize>
fn encoded_fixed_size() -> Option<usize>
source§impl<'de> Deserialize<'de> for Timestamp
impl<'de> Deserialize<'de> for Timestamp
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<Timestamp, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Timestamp, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl Encode for Timestamp
impl Encode for Timestamp
source§fn encode_to<T>(&self, writer: &mut T)where
T: Output + ?Sized,
fn encode_to<T>(&self, writer: &mut T)where
T: Output + ?Sized,
§fn using_encoded<R, F>(&self, f: F) -> R
fn using_encoded<R, F>(&self, f: F) -> R
§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
§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 moresource§impl Serialize for Timestamp
impl Serialize for Timestamp
source§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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§
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
§impl<T> DecodeAll for Twhere
T: Decode,
impl<T> DecodeAll for Twhere
T: Decode,
§fn decode_all(input: &mut &[u8]) -> Result<T, Error>
fn decode_all(input: &mut &[u8]) -> Result<T, Error>
Self
and consume all of the given input data. Read more