pub struct Timestamp { /* private fields */ }
Expand description
A newtype wrapper over PrimitiveDateTime
which serves as the foundational
basis for capturing timestamps. It is used directly to keep track of host
timestamps.
It is also encoded as part of the
ibc::channel::types::timeout::TimeoutTimestamp
type for expressly keeping
track of timeout timestamps.
Implementations§
Source§impl Timestamp
impl Timestamp
pub fn from_nanoseconds(nanoseconds: u64) -> Timestamp
pub fn from_unix_timestamp( secs: u64, nanos: u32, ) -> Result<Timestamp, TimestampError>
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
.
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);
let utx = tx.nanoseconds();
assert_eq!(utx, max);
let min = u64::MIN;
let ti = Timestamp::from_nanoseconds(min);
let uti = ti.nanoseconds();
assert_eq!(uti, min);
Trait Implementations§
Source§impl<'a> Arbitrary<'a> for Timestamp
impl<'a> Arbitrary<'a> for Timestamp
Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Timestamp, Error>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Timestamp, Error>
Generate an arbitrary value of
Self
from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Generate an arbitrary value of
Self
from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Get a size hint for how many bytes out of an
Unstructured
this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Get a size hint for how many bytes out of an
Unstructured
this type
needs to construct itself. Read moreSource§impl BorshDeserialize for Timestamp
impl BorshDeserialize for Timestamp
fn deserialize_reader<R>(reader: &mut R) -> Result<Timestamp, Error>where
R: Read,
Source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Deserializes this instance from a given slice of bytes.
Updates the buffer to point at the remaining bytes.
Source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
Deserialize this instance from a slice of bytes.
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: &mut I) -> Result<Timestamp, Error>where
I: Input,
fn decode<I>(input: &mut I) -> Result<Timestamp, Error>where
I: Input,
Attempt to deserialise the value from input.
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,
Attempt to deserialize the value from input into a pre-allocated piece of memory. Read more
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Encode for Timestamp
impl Encode for Timestamp
Source§fn encode_to<T>(&self, writer: &mut T)
fn encode_to<T>(&self, writer: &mut T)
Convert self to a slice and append it to the destination.
Source§fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
If possible give a hint of expected size of the encoding. Read more
Source§fn using_encoded<R, F>(&self, f: F) -> R
fn using_encoded<R, F>(&self, f: F) -> R
Convert self to a slice and then invoke the given closure with it.
Source§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
Calculates the encoded size. Read more
Source§impl From<Timestamp> for OffsetDateTime
impl From<Timestamp> for OffsetDateTime
Source§fn from(t: Timestamp) -> OffsetDateTime
fn from(t: Timestamp) -> OffsetDateTime
Converts to this type from the input type.
Source§impl From<Timestamp> for TimeoutTimestamp
impl From<Timestamp> for TimeoutTimestamp
Source§fn from(timestamp: Timestamp) -> TimeoutTimestamp
fn from(timestamp: Timestamp) -> TimeoutTimestamp
Converts to this type from the input type.
Source§impl<T> IntoHostTime<T> for Timestampwhere
T: TryFrom<OffsetDateTime>,
impl<T> IntoHostTime<T> for Timestampwhere
T: TryFrom<OffsetDateTime>,
Source§fn into_host_time(self) -> Result<T, TimestampError>
fn into_host_time(self) -> Result<T, TimestampError>
Source§impl JsonSchema for Timestamp
impl JsonSchema for Timestamp
Source§fn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Returns a string that uniquely identifies the schema produced by this type. Read more
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
Whether JSON Schemas generated for this type should be re-used where possible using the
$ref
keyword. Read moreSource§impl Ord for Timestamp
impl Ord for Timestamp
Source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
Source§impl Protobuf<Timestamp> for Timestamp
impl Protobuf<Timestamp> for Timestamp
Source§fn encode<B>(self, buf: &mut B) -> Result<(), Error>where
B: BufMut,
fn encode<B>(self, buf: &mut B) -> Result<(), Error>where
B: BufMut,
Encode into a buffer in Protobuf format. Read more
Source§fn encode_length_delimited<B>(self, buf: &mut B) -> Result<(), Error>where
B: BufMut,
fn encode_length_delimited<B>(self, buf: &mut B) -> Result<(), Error>where
B: BufMut,
Encode with a length-delimiter to a buffer in Protobuf format. Read more
Source§fn decode<B>(buf: B) -> Result<Self, Error>where
B: Buf,
fn decode<B>(buf: B) -> Result<Self, Error>where
B: Buf,
Constructor that attempts to decode an instance from a buffer. Read more
Source§fn decode_length_delimited<B>(buf: B) -> Result<Self, Error>where
B: Buf,
fn decode_length_delimited<B>(buf: B) -> Result<Self, Error>where
B: Buf,
Constructor that attempts to decode a length-delimited instance from
the buffer. Read more
Source§fn encoded_len(self) -> usize
fn encoded_len(self) -> usize
Returns the encoded length of the message without a length delimiter. Read more
Source§fn decode_vec(v: &[u8]) -> Result<Self, Error>
fn decode_vec(v: &[u8]) -> Result<Self, Error>
Constructor that attempts to decode a Protobuf-encoded instance from a
Vec<u8>
(or equivalent).Source§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,
Serialize this value into the given Serde serializer. Read more
Source§impl TryFrom<OffsetDateTime> for Timestamp
impl TryFrom<OffsetDateTime> for Timestamp
Source§type Error = TimestampError
type Error = TimestampError
The type returned in the event of a conversion error.
Source§fn try_from(
t: OffsetDateTime,
) -> Result<Timestamp, <Timestamp as TryFrom<OffsetDateTime>>::Error>
fn try_from( t: OffsetDateTime, ) -> Result<Timestamp, <Timestamp as TryFrom<OffsetDateTime>>::Error>
Performs the conversion.
impl Copy for Timestamp
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 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
Mutably borrows from an owned value. Read more