devela::_dep::jiff::tz

Struct Offset

pub struct Offset { /* private fields */ }
Available on crate features dep_jiff and alloc only.
Expand description

Represents a fixed time zone offset.

Negative offsets correspond to time zones west of the prime meridian, while positive offsets correspond to time zones east of the prime meridian. Equivalently, in all cases, civil-time - offset = UTC.

§Display format

This type implements the std::fmt::Display trait. It will convert the offset to a string format in the form {sign}{hours}[:{minutes}[:{seconds}]], where minutes and seconds are only present when non-zero. For example:

use jiff::tz;

let o = tz::offset(-5);
assert_eq!(o.to_string(), "-05");
let o = tz::Offset::from_seconds(-18_000).unwrap();
assert_eq!(o.to_string(), "-05");
let o = tz::Offset::from_seconds(-18_060).unwrap();
assert_eq!(o.to_string(), "-05:01");
let o = tz::Offset::from_seconds(-18_062).unwrap();
assert_eq!(o.to_string(), "-05:01:02");

// The min value.
let o = tz::Offset::from_seconds(-93_599).unwrap();
assert_eq!(o.to_string(), "-25:59:59");
// The max value.
let o = tz::Offset::from_seconds(93_599).unwrap();
assert_eq!(o.to_string(), "+25:59:59");
// No offset.
let o = tz::offset(0);
assert_eq!(o.to_string(), "+00");

§Example

This shows how to create a zoned datetime with a time zone using a fixed offset:

use jiff::{civil::date, tz, Zoned};

let offset = tz::offset(-4).to_time_zone();
let zdt = date(2024, 7, 8).at(15, 20, 0, 0).to_zoned(offset)?;
assert_eq!(zdt.to_string(), "2024-07-08T15:20:00-04:00[-04:00]");

Notice that the zoned datetime still includes a time zone annotation. But since there is no time zone identifier, the offset instead is repeated as an additional assertion that a fixed offset datetime was intended.

Implementations§

§

impl Offset

pub const MIN: Offset

The minimum possible time zone offset.

This corresponds to the offset -25:59:59.

pub const MAX: Offset

The maximum possible time zone offset.

This corresponds to the offset 25:59:59.

pub const UTC: Offset = Offset::ZERO

The offset corresponding to UTC. That is, no offset at all.

This is defined to always be equivalent to Offset::ZERO, but it is semantically distinct. This ought to be used when UTC is desired specifically, while Offset::ZERO ought to be used when one wants to express “no offset.” For example, when adding offsets, Offset::ZERO corresponds to the identity.

pub const ZERO: Offset

The offset corresponding to no offset at all.

This is defined to always be equivalent to Offset::UTC, but it is semantically distinct. This ought to be used when a zero offset is desired specifically, while Offset::UTC ought to be used when one wants to express UTC. For example, when adding offsets, Offset::ZERO corresponds to the identity.

pub const fn constant(hours: i8) -> Offset

Creates a new time zone offset in a const context from a given number of hours.

Negative offsets correspond to time zones west of the prime meridian, while positive offsets correspond to time zones east of the prime meridian. Equivalently, in all cases, civil-time - offset = UTC.

The fallible non-const version of this constructor is Offset::from_hours.

§Panics

This routine panics when the given number of hours is out of range. Namely, hours must be in the range -25..=25.

§Example
use jiff::tz::Offset;

let o = Offset::constant(-5);
assert_eq!(o.seconds(), -18_000);
let o = Offset::constant(5);
assert_eq!(o.seconds(), 18_000);

Alternatively, one can use the terser jiff::tz::offset free function:

use jiff::tz;

let o = tz::offset(-5);
assert_eq!(o.seconds(), -18_000);
let o = tz::offset(5);
assert_eq!(o.seconds(), 18_000);

pub fn from_hours(hours: i8) -> Result<Offset, Error>

Creates a new time zone offset from a given number of hours.

Negative offsets correspond to time zones west of the prime meridian, while positive offsets correspond to time zones east of the prime meridian. Equivalently, in all cases, civil-time - offset = UTC.

§Errors

This routine returns an error when the given number of hours is out of range. Namely, hours must be in the range -25..=25.

§Example
use jiff::tz::Offset;

let o = Offset::from_hours(-5)?;
assert_eq!(o.seconds(), -18_000);
let o = Offset::from_hours(5)?;
assert_eq!(o.seconds(), 18_000);

pub fn from_seconds(seconds: i32) -> Result<Offset, Error>

Creates a new time zone offset in a const context from a given number of seconds.

Negative offsets correspond to time zones west of the prime meridian, while positive offsets correspond to time zones east of the prime meridian. Equivalently, in all cases, civil-time - offset = UTC.

§Errors

This routine returns an error when the given number of seconds is out of range. The range corresponds to the offsets -25:59:59..=25:59:59. In units of seconds, that corresponds to -93,599..=93,599.

§Example
use jiff::tz::Offset;

let o = Offset::from_seconds(-18_000)?;
assert_eq!(o.seconds(), -18_000);
let o = Offset::from_seconds(18_000)?;
assert_eq!(o.seconds(), 18_000);

pub fn seconds(self) -> i32

Returns the total number of seconds in this offset.

The value returned is guaranteed to represent an offset in the range -25:59:59..=25:59:59. Or more precisely, the value will be in units of seconds in the range -93,599..=93,599.

Negative offsets correspond to time zones west of the prime meridian, while positive offsets correspond to time zones east of the prime meridian. Equivalently, in all cases, civil-time - offset = UTC.

§Example
use jiff::tz;

let o = tz::offset(-5);
assert_eq!(o.seconds(), -18_000);
let o = tz::offset(5);
assert_eq!(o.seconds(), 18_000);

pub fn negate(self) -> Offset

Returns the negation of this offset.

A negative offset will become positive and vice versa. This is a no-op if the offset is zero.

This never panics.

§Example
use jiff::tz;

assert_eq!(tz::offset(-5).negate(), tz::offset(5));
// It's also available via the `-` operator:
assert_eq!(-tz::offset(-5), tz::offset(5));

pub fn signum(self) -> i8

Returns the “sign number” or “signum” of this offset.

The number returned is -1 when this offset is negative, 0 when this offset is zero and 1 when this span is positive.

§Example
use jiff::tz;

assert_eq!(tz::offset(5).signum(), 1);
assert_eq!(tz::offset(0).signum(), 0);
assert_eq!(tz::offset(-5).signum(), -1);

pub fn is_positive(self) -> bool

Returns true if and only if this offset is positive.

This returns false when the offset is zero or negative.

§Example
use jiff::tz;

assert!(tz::offset(5).is_positive());
assert!(!tz::offset(0).is_positive());
assert!(!tz::offset(-5).is_positive());

pub fn is_negative(self) -> bool

Returns true if and only if this offset is less than zero.

§Example
use jiff::tz;

assert!(!tz::offset(5).is_negative());
assert!(!tz::offset(0).is_negative());
assert!(tz::offset(-5).is_negative());

pub fn is_zero(self) -> bool

Returns true if and only if this offset is zero.

Or equivalently, when this offset corresponds to Offset::UTC.

§Example
use jiff::tz;

assert!(!tz::offset(5).is_zero());
assert!(tz::offset(0).is_zero());
assert!(!tz::offset(-5).is_zero());

pub fn to_time_zone(self) -> TimeZone

Converts this offset into a TimeZone.

This is a convenience function for calling TimeZone::fixed with this offset.

§Example
use jiff::tz::offset;

let tz = offset(-4).to_time_zone();
assert_eq!(
    tz.to_datetime(jiff::Timestamp::UNIX_EPOCH).to_string(),
    "1969-12-31T20:00:00",
);

pub fn to_datetime(self, timestamp: Timestamp) -> DateTime

Converts the given timestamp to a civil datetime using this offset.

§Example
use jiff::{civil::date, tz, Timestamp};

assert_eq!(
    tz::offset(-8).to_datetime(Timestamp::UNIX_EPOCH),
    date(1969, 12, 31).at(16, 0, 0, 0),
);

pub fn to_timestamp(self, dt: DateTime) -> Result<Timestamp, Error>

Converts the given civil datetime to a timestamp using this offset.

§Errors

This returns an error if this would have returned a timestamp outside of its minimum and maximum values.

§Example

This example shows how to find the timestamp corresponding to 1969-12-31T16:00:00-08.

use jiff::{civil::date, tz, Timestamp};

assert_eq!(
    tz::offset(-8).to_timestamp(date(1969, 12, 31).at(16, 0, 0, 0))?,
    Timestamp::UNIX_EPOCH,
);

This example shows some maximum boundary conditions where this routine will fail:

use jiff::{civil::date, tz, Timestamp, ToSpan};

let dt = date(9999, 12, 31).at(23, 0, 0, 0);
assert!(tz::offset(-8).to_timestamp(dt).is_err());

// If the offset is big enough, then converting it to a UTC
// timestamp will fit, even when using the maximum civil datetime.
let dt = date(9999, 12, 31).at(23, 59, 59, 999_999_999);
assert_eq!(tz::Offset::MAX.to_timestamp(dt).unwrap(), Timestamp::MAX);
// But adjust the offset down 1 second is enough to go out-of-bounds.
assert!((tz::Offset::MAX - 1.seconds()).to_timestamp(dt).is_err());

Same as above, but for minimum values:

use jiff::{civil::date, tz, Timestamp, ToSpan};

let dt = date(-9999, 1, 1).at(1, 0, 0, 0);
assert!(tz::offset(8).to_timestamp(dt).is_err());

// If the offset is small enough, then converting it to a UTC
// timestamp will fit, even when using the minimum civil datetime.
let dt = date(-9999, 1, 1).at(0, 0, 0, 0);
assert_eq!(tz::Offset::MIN.to_timestamp(dt).unwrap(), Timestamp::MIN);
// But adjust the offset up 1 second is enough to go out-of-bounds.
assert!((tz::Offset::MIN + 1.seconds()).to_timestamp(dt).is_err());

pub fn checked_add<A>(self, duration: A) -> Result<Offset, Error>

Adds the given span of time to this offset.

Since time zone offsets have second resolution, any fractional seconds in the duration given are ignored.

This operation accepts three different duration types: Span, SignedDuration or std::time::Duration. This is achieved via From trait implementations for the OffsetArithmetic type.

§Errors

This returns an error if the result of adding the given span would exceed the minimum or maximum allowed Offset value.

This also returns an error if the span given contains any non-zero units bigger than hours.

§Example

This example shows how to add one hour to an offset (if the offset corresponds to standard time, then adding an hour will usually give you DST time):

use jiff::{tz, ToSpan};

let off = tz::offset(-5);
assert_eq!(off.checked_add(1.hours()).unwrap(), tz::offset(-4));

And note that while fractional seconds are ignored, units less than seconds aren’t ignored if they sum up to a duration at least as big as one second:

use jiff::{tz, ToSpan};

let off = tz::offset(5);
let span = 900.milliseconds()
    .microseconds(50_000)
    .nanoseconds(50_000_000);
assert_eq!(
    off.checked_add(span).unwrap(),
    tz::Offset::from_seconds((5 * 60 * 60) + 1).unwrap(),
);
// Any leftover fractional part is ignored.
let span = 901.milliseconds()
    .microseconds(50_001)
    .nanoseconds(50_000_001);
assert_eq!(
    off.checked_add(span).unwrap(),
    tz::Offset::from_seconds((5 * 60 * 60) + 1).unwrap(),
);

This example shows some cases where checked addition will fail.

use jiff::{tz::Offset, ToSpan};

// Adding units above 'hour' always results in an error.
assert!(Offset::UTC.checked_add(1.day()).is_err());
assert!(Offset::UTC.checked_add(1.week()).is_err());
assert!(Offset::UTC.checked_add(1.month()).is_err());
assert!(Offset::UTC.checked_add(1.year()).is_err());

// Adding even 1 second to the max, or subtracting 1 from the min,
// will result in overflow and thus an error will be returned.
assert!(Offset::MIN.checked_add(-1.seconds()).is_err());
assert!(Offset::MAX.checked_add(1.seconds()).is_err());
§Example: adding absolute durations

This shows how to add signed and unsigned absolute durations to an Offset. Like with Spans, any fractional seconds are ignored.

use std::time::Duration;

use jiff::{tz::offset, SignedDuration};

let off = offset(-10);

let dur = SignedDuration::from_hours(11);
assert_eq!(off.checked_add(dur)?, offset(1));
assert_eq!(off.checked_add(-dur)?, offset(-21));

// Any leftover time is truncated. That is, only
// whole seconds from the duration are considered.
let dur = Duration::new(3 * 60 * 60, 999_999_999);
assert_eq!(off.checked_add(dur)?, offset(-7));

pub fn checked_sub<A>(self, duration: A) -> Result<Offset, Error>

This routine is identical to Offset::checked_add with the duration negated.

§Errors

This has the same error conditions as Offset::checked_add.

§Example
use std::time::Duration;

use jiff::{tz, SignedDuration, ToSpan};

let off = tz::offset(-4);
assert_eq!(
    off.checked_sub(1.hours())?,
    tz::offset(-5),
);
assert_eq!(
    off.checked_sub(SignedDuration::from_hours(1))?,
    tz::offset(-5),
);
assert_eq!(
    off.checked_sub(Duration::from_secs(60 * 60))?,
    tz::offset(-5),
);

pub fn saturating_add<A>(self, duration: A) -> Offset

This routine is identical to Offset::checked_add, except the result saturates on overflow. That is, instead of overflow, either Offset::MIN or Offset::MAX is returned.

§Example

This example shows some cases where saturation will occur.

use jiff::{tz::Offset, SignedDuration, ToSpan};

// Adding units above 'day' always results in saturation.
assert_eq!(Offset::UTC.saturating_add(1.weeks()), Offset::MAX);
assert_eq!(Offset::UTC.saturating_add(1.months()), Offset::MAX);
assert_eq!(Offset::UTC.saturating_add(1.years()), Offset::MAX);

// Adding even 1 second to the max, or subtracting 1 from the min,
// will result in saturationg.
assert_eq!(Offset::MIN.saturating_add(-1.seconds()), Offset::MIN);
assert_eq!(Offset::MAX.saturating_add(1.seconds()), Offset::MAX);

// Adding absolute durations also saturates as expected.
assert_eq!(Offset::UTC.saturating_add(SignedDuration::MAX), Offset::MAX);
assert_eq!(Offset::UTC.saturating_add(SignedDuration::MIN), Offset::MIN);
assert_eq!(Offset::UTC.saturating_add(std::time::Duration::MAX), Offset::MAX);

pub fn saturating_sub<A>(self, duration: A) -> Offset

This routine is identical to Offset::saturating_add with the span parameter negated.

§Example

This example shows some cases where saturation will occur.

use jiff::{tz::Offset, SignedDuration, ToSpan};

// Adding units above 'day' always results in saturation.
assert_eq!(Offset::UTC.saturating_sub(1.weeks()), Offset::MIN);
assert_eq!(Offset::UTC.saturating_sub(1.months()), Offset::MIN);
assert_eq!(Offset::UTC.saturating_sub(1.years()), Offset::MIN);

// Adding even 1 second to the max, or subtracting 1 from the min,
// will result in saturationg.
assert_eq!(Offset::MIN.saturating_sub(1.seconds()), Offset::MIN);
assert_eq!(Offset::MAX.saturating_sub(-1.seconds()), Offset::MAX);

// Adding absolute durations also saturates as expected.
assert_eq!(Offset::UTC.saturating_sub(SignedDuration::MAX), Offset::MIN);
assert_eq!(Offset::UTC.saturating_sub(SignedDuration::MIN), Offset::MAX);
assert_eq!(Offset::UTC.saturating_sub(std::time::Duration::MAX), Offset::MIN);

pub fn until(self, other: Offset) -> Span

Returns the span of time from this offset until the other given.

When the other offset is more west (i.e., more negative) of the prime meridian than this offset, then the span returned will be negative.

§Properties

Adding the span returned to this offset will always equal the other offset given.

§Examples
use jiff::{tz, ToSpan};

assert_eq!(
    tz::offset(-5).until(tz::Offset::UTC),
    (5 * 60 * 60).seconds(),
);
// Flipping the operands in this case results in a negative span.
assert_eq!(
    tz::Offset::UTC.until(tz::offset(-5)),
    -(5 * 60 * 60).seconds(),
);

pub fn since(self, other: Offset) -> Span

Returns the span of time since the other offset given from this offset.

When the other is more east (i.e., more positive) of the prime meridian than this offset, then the span returned will be negative.

§Properties

Adding the span returned to the other offset will always equal this offset.

§Examples
use jiff::{tz, ToSpan};

assert_eq!(
    tz::Offset::UTC.since(tz::offset(-5)),
    (5 * 60 * 60).seconds(),
);
// Flipping the operands in this case results in a negative span.
assert_eq!(
    tz::offset(-5).since(tz::Offset::UTC),
    -(5 * 60 * 60).seconds(),
);

pub fn duration_until(self, other: Offset) -> SignedDuration

Returns an absolute duration representing the difference in time from this offset until the given other offset.

When the other offset is more west (i.e., more negative) of the prime meridian than this offset, then the duration returned will be negative.

Unlike Offset::until, this returns a duration corresponding to a 96-bit integer of nanoseconds between two offsets.

§When should I use this versus Offset::until?

See the type documentation for SignedDuration for the section on when one should use Span and when one should use SignedDuration. In short, use Span (and therefore Offset::until) unless you have a specific reason to do otherwise.

§Examples
use jiff::{tz, SignedDuration};

assert_eq!(
    tz::offset(-5).duration_until(tz::Offset::UTC),
    SignedDuration::from_hours(5),
);
// Flipping the operands in this case results in a negative span.
assert_eq!(
    tz::Offset::UTC.duration_until(tz::offset(-5)),
    SignedDuration::from_hours(-5),
);

pub fn duration_since(self, other: Offset) -> SignedDuration

This routine is identical to Offset::duration_until, but the order of the parameters is flipped.

§Examples
use jiff::{tz, SignedDuration};

assert_eq!(
    tz::Offset::UTC.duration_since(tz::offset(-5)),
    SignedDuration::from_hours(5),
);
assert_eq!(
    tz::offset(-5).duration_since(tz::Offset::UTC),
    SignedDuration::from_hours(-5),
);

Trait Implementations§

§

impl Add<Duration> for Offset

Adds an unsigned duration of time to an offset. This panics on overflow.

For checked arithmetic, see Offset::checked_add.

§

type Output = Offset

The resulting type after applying the + operator.
§

fn add(self, rhs: Duration) -> Offset

Performs the + operation. Read more
§

impl Add<SignedDuration> for Offset

Adds a signed duration of time to an offset. This panics on overflow.

For checked arithmetic, see Offset::checked_add.

§

type Output = Offset

The resulting type after applying the + operator.
§

fn add(self, rhs: SignedDuration) -> Offset

Performs the + operation. Read more
§

impl Add<Span> for Offset

Adds a span of time to an offset. This panics on overflow.

For checked arithmetic, see Offset::checked_add.

§

type Output = Offset

The resulting type after applying the + operator.
§

fn add(self, rhs: Span) -> Offset

Performs the + operation. Read more
§

impl AddAssign<Duration> for Offset

Adds an unsigned duration of time to an offset in place. This panics on overflow.

For checked arithmetic, see Offset::checked_add.

§

fn add_assign(&mut self, rhs: Duration)

Performs the += operation. Read more
§

impl AddAssign<SignedDuration> for Offset

Adds a signed duration of time to an offset in place. This panics on overflow.

For checked arithmetic, see Offset::checked_add.

§

fn add_assign(&mut self, rhs: SignedDuration)

Performs the += operation. Read more
§

impl AddAssign<Span> for Offset

Adds a span of time to an offset in place. This panics on overflow.

For checked arithmetic, see Offset::checked_add.

§

fn add_assign(&mut self, rhs: Span)

Performs the += operation. Read more
§

impl Clone for Offset

§

fn clone(&self) -> Offset

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
§

impl Debug for Offset

§

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

Formats the value using the given formatter. Read more
§

impl Display for Offset

§

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

Formats the value using the given formatter. Read more
§

impl From<Offset> for PiecesNumericOffset

§

fn from(offset: Offset) -> PiecesNumericOffset

Converts to this type from the input type.
§

impl From<Offset> for PiecesOffset

§

fn from(offset: Offset) -> PiecesOffset

Converts to this type from the input type.
§

impl From<Offset> for TimeZoneAnnotation<'static>

§

fn from(offset: Offset) -> TimeZoneAnnotation<'static>

Converts to this type from the input type.
§

impl From<Offset> for TimeZoneAnnotationKind<'static>

§

fn from(offset: Offset) -> TimeZoneAnnotationKind<'static>

Converts to this type from the input type.
§

impl Hash for Offset

§

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 Neg for Offset

Negate this offset.

A positive offset becomes negative and vice versa. This is a no-op for the zero offset.

This never panics.

§

type Output = Offset

The resulting type after applying the - operator.
§

fn neg(self) -> Offset

Performs the unary - operation. Read more
§

impl Ord for Offset

§

fn cmp(&self, other: &Offset) -> 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,

Restrict a value to a certain interval. Read more
§

impl PartialEq for Offset

§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

impl PartialOrd for Offset

§

fn partial_cmp(&self, other: &Offset) -> 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

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

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

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

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

impl Sub<Duration> for Offset

Subtracts an unsigned duration of time from an offset. This panics on overflow.

For checked arithmetic, see Offset::checked_sub.

§

type Output = Offset

The resulting type after applying the - operator.
§

fn sub(self, rhs: Duration) -> Offset

Performs the - operation. Read more
§

impl Sub<SignedDuration> for Offset

Subtracts a signed duration of time from an offset. This panics on overflow.

For checked arithmetic, see Offset::checked_sub.

§

type Output = Offset

The resulting type after applying the - operator.
§

fn sub(self, rhs: SignedDuration) -> Offset

Performs the - operation. Read more
§

impl Sub<Span> for Offset

Subtracts a span of time from an offset. This panics on overflow.

For checked arithmetic, see Offset::checked_sub.

§

type Output = Offset

The resulting type after applying the - operator.
§

fn sub(self, rhs: Span) -> Offset

Performs the - operation. Read more
§

impl Sub for Offset

Computes the span of time between two offsets.

This will return a negative span when the offset being subtracted is greater (i.e., more east with respect to the prime meridian).

§

type Output = Span

The resulting type after applying the - operator.
§

fn sub(self, rhs: Offset) -> Span

Performs the - operation. Read more
§

impl SubAssign<Duration> for Offset

Subtracts an unsigned duration of time from an offset in place. This panics on overflow.

For checked arithmetic, see Offset::checked_sub.

§

fn sub_assign(&mut self, rhs: Duration)

Performs the -= operation. Read more
§

impl SubAssign<SignedDuration> for Offset

Subtracts a signed duration of time from an offset in place. This panics on overflow.

For checked arithmetic, see Offset::checked_sub.

§

fn sub_assign(&mut self, rhs: SignedDuration)

Performs the -= operation. Read more
§

impl SubAssign<Span> for Offset

Subtracts a span of time from an offset in place. This panics on overflow.

For checked arithmetic, see Offset::checked_sub.

§

fn sub_assign(&mut self, rhs: Span)

Performs the -= operation. Read more
§

impl Copy for Offset

§

impl Eq for Offset

§

impl StructuralPartialEq for Offset

Auto Trait Implementations§

§

impl Freeze for Offset

§

impl RefUnwindSafe for Offset

§

impl Send for Offset

§

impl Sync for Offset

§

impl Unpin for Offset

§

impl UnwindSafe for Offset

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> ByteSized for T

Source§

const BYTE_ALIGN: usize = _

The alignment of this type in bytes.
Source§

const BYTE_SIZE: usize = _

The size of this type in bytes.
Source§

fn byte_align(&self) -> usize

Returns the alignment of this type in bytes.
Source§

fn byte_size(&self) -> usize

Returns the size of this type in bytes. Read more
Source§

fn ptr_size_ratio(&self) -> [usize; 2]

Returns the size ratio between Ptr::BYTES and BYTE_SIZE. Read more
Source§

impl<T, R> Chain<R> for T
where T: ?Sized,

Source§

fn chain<F>(self, f: F) -> R
where F: FnOnce(Self) -> R, Self: Sized,

Chain a function which takes the parameter by value.
Source§

fn chain_ref<F>(&self, f: F) -> R
where F: FnOnce(&Self) -> R,

Chain a function which takes the parameter by shared reference.
Source§

fn chain_mut<F>(&mut self, f: F) -> R
where F: FnOnce(&mut Self) -> R,

Chain a function which takes the parameter by exclusive reference.
Source§

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> ExtAny for T
where T: Any + ?Sized,

Source§

fn type_id() -> TypeId

Returns the TypeId of Self. Read more
Source§

fn type_of(&self) -> TypeId

Returns the TypeId of self. Read more
Source§

fn type_name(&self) -> &'static str

Returns the type name of self. Read more
Source§

fn type_is<T: 'static>(&self) -> bool

Returns true if Self is of type T. Read more
Source§

fn as_any_ref(&self) -> &dyn Any
where Self: Sized,

Upcasts &self as &dyn Any. Read more
Source§

fn as_any_mut(&mut self) -> &mut dyn Any
where Self: Sized,

Upcasts &mut self as &mut dyn Any. Read more
Source§

fn as_any_box(self: Box<Self>) -> Box<dyn Any>
where Self: Sized,

Upcasts Box<self> as Box<dyn Any>. Read more
Source§

fn downcast_ref<T: 'static>(&self) -> Option<&T>

Available on crate feature unsafe_layout only.
Returns some shared reference to the inner value if it is of type T. Read more
Source§

fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T>

Available on crate feature unsafe_layout only.
Returns some exclusive reference to the inner value if it is of type T. Read more
Source§

impl<T> ExtMem for T
where T: ?Sized,

Source§

const NEEDS_DROP: bool = _

Know whether dropping values of this type matters, in compile-time.
Source§

fn mem_align_of<T>() -> usize

Returns the minimum alignment of the type in bytes. Read more
Source§

fn mem_align_of_val(&self) -> usize

Returns the alignment of the pointed-to value in bytes. Read more
Source§

fn mem_size_of<T>() -> usize

Returns the size of a type in bytes. Read more
Source§

fn mem_size_of_val(&self) -> usize

Returns the size of the pointed-to value in bytes. Read more
Source§

fn mem_copy(&self) -> Self
where Self: Copy,

Bitwise-copies a value. Read more
Source§

fn mem_needs_drop(&self) -> bool

Returns true if dropping values of this type matters. Read more
Source§

fn mem_drop(self)
where Self: Sized,

Drops self by running its destructor. Read more
Source§

fn mem_forget(self)
where Self: Sized,

Forgets about self without running its destructor. Read more
Source§

fn mem_replace(&mut self, other: Self) -> Self
where Self: Sized,

Replaces self with other, returning the previous value of self. Read more
Source§

fn mem_take(&mut self) -> Self
where Self: Default,

Replaces self with its default value, returning the previous value of self. Read more
Source§

fn mem_swap(&mut self, other: &mut Self)
where Self: Sized,

Swaps the value of self and other without deinitializing either one. Read more
Source§

unsafe fn mem_zeroed<T>() -> T

Available on crate feature unsafe_layout only.
Returns the value of type T represented by the all-zero byte-pattern. Read more
Source§

unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst

Available on crate feature unsafe_layout only.
Returns the value of type T represented by the all-zero byte-pattern. Read more
Source§

fn mem_as_bytes(&self) -> &[u8]
where Self: Sync + Unpin,

Available on crate feature unsafe_slice only.
View a Sync + Unpin self as &[u8]. Read more
Source§

fn mem_as_bytes_mut(&mut self) -> &mut [u8]
where Self: Sync + Unpin,

Available on crate feature unsafe_slice only.
View a Sync + Unpin self as &mut [u8]. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

Source§

impl<T> Hook for T

Source§

fn hook_ref<F>(self, f: F) -> Self
where F: FnOnce(&Self),

Applies a function which takes the parameter by shared reference, and then returns the (possibly) modified owned value. Read more
Source§

fn hook_mut<F>(self, f: F) -> Self
where F: FnOnce(&mut Self),

Applies a function which takes the parameter by exclusive reference, and then returns the (possibly) modified owned value. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> LayoutRaw for T

§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Pointee for T

§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

§

impl<T> Ungil for T
where T: Send,