Type Alias bones_framework::prelude::Instant

pub type Instant = Instant;

Aliased Type§

struct Instant(/* private fields */);

Implementations

source§

impl Instant

1.8.0 · source

pub fn now() -> Instant

Returns an instant corresponding to “now”.

§Examples
use std::time::Instant;

let now = Instant::now();
1.8.0 · source

pub fn duration_since(&self, earlier: Instant) -> Duration

Returns the amount of time elapsed from another instant to this one, or zero duration if that instant is later than this one.

§Panics

Previous Rust versions panicked when earlier was later than self. Currently this method saturates. Future versions may reintroduce the panic in some circumstances. See Monotonicity.

§Examples
use std::time::{Duration, Instant};
use std::thread::sleep;

let now = Instant::now();
sleep(Duration::new(1, 0));
let new_now = Instant::now();
println!("{:?}", new_now.duration_since(now));
println!("{:?}", now.duration_since(new_now)); // 0ns
1.39.0 · source

pub fn checked_duration_since(&self, earlier: Instant) -> Option<Duration>

Returns the amount of time elapsed from another instant to this one, or None if that instant is later than this one.

Due to monotonicity bugs, even under correct logical ordering of the passed Instants, this method can return None.

§Examples
use std::time::{Duration, Instant};
use std::thread::sleep;

let now = Instant::now();
sleep(Duration::new(1, 0));
let new_now = Instant::now();
println!("{:?}", new_now.checked_duration_since(now));
println!("{:?}", now.checked_duration_since(new_now)); // None
1.39.0 · source

pub fn saturating_duration_since(&self, earlier: Instant) -> Duration

Returns the amount of time elapsed from another instant to this one, or zero duration if that instant is later than this one.

§Examples
use std::time::{Duration, Instant};
use std::thread::sleep;

let now = Instant::now();
sleep(Duration::new(1, 0));
let new_now = Instant::now();
println!("{:?}", new_now.saturating_duration_since(now));
println!("{:?}", now.saturating_duration_since(new_now)); // 0ns
1.8.0 · source

pub fn elapsed(&self) -> Duration

Returns the amount of time elapsed since this instant.

§Panics

Previous Rust versions panicked when the current time was earlier than self. Currently this method returns a Duration of zero in that case. Future versions may reintroduce the panic. See Monotonicity.

§Examples
use std::thread::sleep;
use std::time::{Duration, Instant};

let instant = Instant::now();
let three_secs = Duration::from_secs(3);
sleep(three_secs);
assert!(instant.elapsed() >= three_secs);
1.34.0 · source

pub fn checked_add(&self, duration: Duration) -> Option<Instant>

Returns Some(t) where t is the time self + duration if t can be represented as Instant (which means it’s inside the bounds of the underlying data structure), None otherwise.

1.34.0 · source

pub fn checked_sub(&self, duration: Duration) -> Option<Instant>

Returns Some(t) where t is the time self - duration if t can be represented as Instant (which means it’s inside the bounds of the underlying data structure), None otherwise.

Trait Implementations

§

impl Add<Duration> for Instant

§

type Output = Instant

The resulting type after applying the + operator.
§

fn add(self, duration: Duration) -> <Instant as Add<Duration>>::Output

Performs the + operation. Read more
1.8.0 · source§

impl Add<Duration> for Instant

source§

fn add(self, other: Duration) -> Instant

§Panics

This function may panic if the resulting point in time cannot be represented by the underlying data structure. See Instant::checked_add for a version without panic.

§

type Output = Instant

The resulting type after applying the + operator.
§

impl Add<Nanos> for Instant

§

type Output = Instant

The resulting type after applying the + operator.
§

fn add(self, other: Nanos) -> Instant

Performs the + operation. Read more
§

impl AddAssign<Duration> for Instant

§

fn add_assign(&mut self, rhs: Duration)

Performs the += operation. Read more
1.9.0 · source§

impl AddAssign<Duration> for Instant

source§

fn add_assign(&mut self, other: Duration)

Performs the += operation. Read more
1.8.0 · source§

impl Clone for Instant

source§

fn clone(&self) -> Instant

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
1.8.0 · source§

impl Debug for Instant

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl From<Instant> for Instant

§

fn from(instant: Instant) -> Instant

Converts to this type from the input type.
§

impl From<Instant> for Instant

§

fn from(time: Instant) -> Instant

Converts to this type from the input type.
1.8.0 · source§

impl Hash for Instant

source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl InstantExt for Instant

§

fn checked_add_signed(&self, duration: Duration) -> Option<Instant>

Returns Some(t) where t is the time self.checked_add_signed(duration) if t can be represented as Instant (which means it’s inside the bounds of the underlying data structure), None otherwise.
§

fn checked_sub_signed(&self, duration: Duration) -> Option<Instant>

Returns Some(t) where t is the time self.checked_sub_signed(duration) if t can be represented as Instant (which means it’s inside the bounds of the underlying data structure), None otherwise.
§

fn signed_duration_since(&self, earlier: Instant) -> Duration

Returns the amount of time elapsed from another instant to this one. This will be negative if earlier is later than self. Read more
§

fn add_signed(self, duration: Duration) -> Self

Panics Read more
§

fn sub_signed(self, duration: Duration) -> Self

Panics Read more
1.8.0 · source§

impl Ord for Instant

source§

fn cmp(&self, other: &Instant) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
§

impl PartialEq<Instant> for Instant

§

fn eq(&self, rhs: &Instant) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
1.8.0 · source§

impl PartialEq for Instant

source§

fn eq(&self, other: &Instant) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialOrd<Instant> for Instant

§

fn partial_cmp(&self, rhs: &Instant) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
1.8.0 · source§

impl PartialOrd for Instant

source§

fn partial_cmp(&self, other: &Instant) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl Reference for Instant

§

fn duration_since(&self, earlier: Instant) -> Nanos

Determines the time that separates two measurements of a clock. Implementations of this must perform a saturating subtraction - if the earlier timestamp should be later, duration_since must return the zero duration.
§

fn saturating_sub(&self, duration: Nanos) -> Instant

Returns a reference point that lies at most duration in the past from the current reference. If an underflow should occur, returns the current reference.
§

impl Sub<Duration> for Instant

§

type Output = Instant

The resulting type after applying the - operator.
§

fn sub(self, duration: Duration) -> <Instant as Sub<Duration>>::Output

Performs the - operation. Read more
1.8.0 · source§

impl Sub<Duration> for Instant

§

type Output = Instant

The resulting type after applying the - operator.
source§

fn sub(self, other: Duration) -> Instant

Performs the - operation. Read more
§

impl Sub<Instant> for Instant

§

type Output = Duration

The resulting type after applying the - operator.
§

fn sub(self, other: Instant) -> <Instant as Sub<Instant>>::Output

Performs the - operation. Read more
1.8.0 · source§

impl Sub for Instant

source§

fn sub(self, other: Instant) -> Duration

Returns the amount of time elapsed from another instant to this one, or zero duration if that instant is later than this one.

§Panics

Previous Rust versions panicked when other was later than self. Currently this method saturates. Future versions may reintroduce the panic in some circumstances. See Monotonicity.

§

type Output = Duration

The resulting type after applying the - operator.
§

impl SubAssign<Duration> for Instant

§

fn sub_assign(&mut self, rhs: Duration)

Performs the -= operation. Read more
1.9.0 · source§

impl SubAssign<Duration> for Instant

source§

fn sub_assign(&mut self, other: Duration)

Performs the -= operation. Read more
1.8.0 · source§

impl Copy for Instant

1.8.0 · source§

impl Eq for Instant

1.8.0 · source§

impl StructuralPartialEq for Instant