Struct Delay

pub struct Delay { /* private fields */ }

The delay of a frame relative to the previous one.

The ratio is reduced on construction which means equality comparisons is reliable even when mixing different bases. Note however that there is an upper limit to the delays that can be represented exactly when using Self::from_saturating_duration which depends on the granularity of the interval.

use image::Delay;
let delay_10ms = Delay::from_numer_denom_ms(10, 1);
let delay_10000us = Delay::from_numer_denom_ms(10_000, 1_000);

assert_eq!(delay_10ms, delay_10000us);

Implementations

impl Delay

fn from_numer_denom_ms(numerator: u32, denominator: u32) -> Self

Create a delay from a ratio of milliseconds.

Examples

use image::Delay;
let delay_10ms = Delay::from_numer_denom_ms(10, 1);
fn from_saturating_duration(duration: Duration) -> Self

Convert from a duration, clamped between 0 and an implemented defined maximum.

The maximum is at least i32::MAX milliseconds. It should be noted that the accuracy of the result may be relative and very large delays have a coarse resolution.

Examples

use std::time::Duration;
use image::Delay;

let duration = Duration::from_millis(20);
let delay = Delay::from_saturating_duration(duration);
fn numer_denom_ms(self) -> (u32, u32)

The numerator and denominator of the delay in milliseconds.

This is guaranteed to be an exact conversion if the Delay was previously created with the from_numer_denom_ms constructor.

Trait Implementations

impl Clone for Delay

fn clone(&self) -> Self

impl Copy for Delay

impl Debug for Delay

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

impl Eq for Delay

impl PartialEq for Delay

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

impl PartialOrd for Delay

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

impl StructuralPartialEq for Delay

Auto Trait Implementations

impl Freeze for Delay

impl RefUnwindSafe for Delay

impl Send for Delay

impl Sync for Delay

impl Unpin for Delay

impl UnsafeUnpin for Delay

impl UnwindSafe for Delay

Blanket Implementations

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for Delay where ST: ?Sized, DT: ?Sized,

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for Delay where ST: ?Sized, DT: ?Sized,

impl<T> Any for Delay where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Delay where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Delay where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for Delay where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for Delay

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> IntoEither for Delay

impl<T> Pointable for Delay

const ALIGN: usize = _;
type Init = T;
unsafe fn init(init: <T as Pointable>::Init) -> usize
unsafe fn deref<'a>(ptr: usize) -> &'a T
unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
unsafe fn drop(ptr: usize)

impl<T> Read<Exclusive, BecauseExclusive> for Delay where T: ?Sized,

impl<T> ToOwned for Delay where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for Delay where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for Delay where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Delay where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>