Struct sqlx::types::chrono::NaiveTime[][src]

pub struct NaiveTime { /* fields omitted */ }
Expand description

ISO 8601 time without timezone. Allows for the nanosecond precision and optional leap second representation.

Leap Second Handling

Since 1960s, the manmade atomic clock has been so accurate that it is much more accurate than Earth’s own motion. It became desirable to define the civil time in terms of the atomic clock, but that risks the desynchronization of the civil time from Earth. To account for this, the designers of the Coordinated Universal Time (UTC) made that the UTC should be kept within 0.9 seconds of the observed Earth-bound time. When the mean solar day is longer than the ideal (86,400 seconds), the error slowly accumulates and it is necessary to add a leap second to slow the UTC down a bit. (We may also remove a second to speed the UTC up a bit, but it never happened.) The leap second, if any, follows 23:59:59 of June 30 or December 31 in the UTC.

Fast forward to the 21st century, we have seen 26 leap seconds from January 1972 to December 2015. Yes, 26 seconds. Probably you can read this paragraph within 26 seconds. But those 26 seconds, and possibly more in the future, are never predictable, and whether to add a leap second or not is known only before 6 months. Internet-based clocks (via NTP) do account for known leap seconds, but the system API normally doesn’t (and often can’t, with no network connection) and there is no reliable way to retrieve leap second information.

Chrono does not try to accurately implement leap seconds; it is impossible. Rather, it allows for leap seconds but behaves as if there are no other leap seconds. Various operations will ignore any possible leap second(s) except when any of the operands were actually leap seconds.

If you cannot tolerate this behavior, you must use a separate TimeZone for the International Atomic Time (TAI). TAI is like UTC but has no leap seconds, and thus slightly differs from UTC. Chrono does not yet provide such implementation, but it is planned.

Representing Leap Seconds

The leap second is indicated via fractional seconds more than 1 second. This makes possible to treat a leap second as the prior non-leap second if you don’t care about sub-second accuracy. You should use the proper formatting to get the raw leap second.

All methods accepting fractional seconds will accept such values.

use chrono::{NaiveDate, NaiveTime, Utc, TimeZone};

let t = NaiveTime::from_hms_milli(8, 59, 59, 1_000);

let dt1 = NaiveDate::from_ymd(2015, 7, 1).and_hms_micro(8, 59, 59, 1_000_000);

let dt2 = Utc.ymd(2015, 6, 30).and_hms_nano(23, 59, 59, 1_000_000_000);

Note that the leap second can happen anytime given an appropriate time zone; 2015-07-01 01:23:60 would be a proper leap second if UTC+01:24 had existed. Practically speaking, though, by the time of the first leap second on 1972-06-30, every time zone offset around the world has standardized to the 5-minute alignment.

Date And Time Arithmetics

As a concrete example, let’s assume that 03:00:60 and 04:00:60 are leap seconds. In reality, of course, leap seconds are separated by at least 6 months. We will also use some intuitive concise notations for the explanation.

Time + Duration (short for NaiveTime::overflowing_add_signed):

  • 03:00:00 + 1s = 03:00:01.
  • 03:00:59 + 60s = 03:02:00.
  • 03:00:59 + 1s = 03:01:00.
  • 03:00:60 + 1s = 03:01:00. Note that the sum is identical to the previous.
  • 03:00:60 + 60s = 03:01:59.
  • 03:00:60 + 61s = 03:02:00.
  • 03:00:60.1 + 0.8s = 03:00:60.9.

Time - Duration (short for NaiveTime::overflowing_sub_signed):

  • 03:00:00 - 1s = 02:59:59.
  • 03:01:00 - 1s = 03:00:59.
  • 03:01:00 - 60s = 03:00:00.
  • 03:00:60 - 60s = 03:00:00. Note that the result is identical to the previous.
  • 03:00:60.7 - 0.4s = 03:00:60.3.
  • 03:00:60.7 - 0.9s = 03:00:59.8.

Time - Time (short for NaiveTime::signed_duration_since):

  • 04:00:00 - 03:00:00 = 3600s.
  • 03:01:00 - 03:00:00 = 60s.
  • 03:00:60 - 03:00:00 = 60s. Note that the difference is identical to the previous.
  • 03:00:60.6 - 03:00:59.4 = 1.2s.
  • 03:01:00 - 03:00:59.8 = 0.2s.
  • 03:01:00 - 03:00:60.5 = 0.5s. Note that the difference is larger than the previous, even though the leap second clearly follows the previous whole second.
  • 04:00:60.9 - 03:00:60.1 = (04:00:60.9 - 04:00:00) + (04:00:00 - 03:01:00) + (03:01:00 - 03:00:60.1) = 60.9s + 3540s + 0.9s = 3601.8s.

In general,

  • Time + Duration unconditionally equals to Duration + Time.

  • Time - Duration unconditionally equals to Time + (-Duration).

  • Time1 - Time2 unconditionally equals to -(Time2 - Time1).

  • Associativity does not generally hold, because (Time + Duration1) - Duration2 no longer equals to Time + (Duration1 - Duration2) for two positive durations.

    • As a special case, (Time + Duration) - Duration also does not equal to Time.

    • If you can assume that all durations have the same sign, however, then the associativity holds: (Time + Duration1) + Duration2 equals to Time + (Duration1 + Duration2) for two positive durations.

Reading And Writing Leap Seconds

The “typical” leap seconds on the minute boundary are correctly handled both in the formatting and parsing. The leap second in the human-readable representation will be represented as the second part being 60, as required by ISO 8601.

use chrono::{Utc, TimeZone};

let dt = Utc.ymd(2015, 6, 30).and_hms_milli(23, 59, 59, 1_000);
assert_eq!(format!("{:?}", dt), "2015-06-30T23:59:60Z");

There are hypothetical leap seconds not on the minute boundary nevertheless supported by Chrono. They are allowed for the sake of completeness and consistency; there were several “exotic” time zone offsets with fractional minutes prior to UTC after all. For such cases the human-readable representation is ambiguous and would be read back to the next non-leap second.

use chrono::{DateTime, Utc, TimeZone};

let dt = Utc.ymd(2015, 6, 30).and_hms_milli(23, 56, 4, 1_000);
assert_eq!(format!("{:?}", dt), "2015-06-30T23:56:05Z");

let dt = Utc.ymd(2015, 6, 30).and_hms(23, 56, 5);
assert_eq!(format!("{:?}", dt), "2015-06-30T23:56:05Z");
assert_eq!(DateTime::parse_from_rfc3339("2015-06-30T23:56:05Z").unwrap(), dt);

Since Chrono alone cannot determine any existence of leap seconds, there is absolutely no guarantee that the leap second read has actually happened.

Implementations

impl NaiveTime[src]

pub fn from_hms(hour: u32, min: u32, sec: u32) -> NaiveTime[src]

Makes a new NaiveTime from hour, minute and second.

No leap second is allowed here; use NaiveTime::from_hms_* methods with a subsecond parameter instead.

Panics on invalid hour, minute and/or second.

Example

use chrono::{NaiveTime, Timelike};

let t = NaiveTime::from_hms(23, 56, 4);
assert_eq!(t.hour(), 23);
assert_eq!(t.minute(), 56);
assert_eq!(t.second(), 4);
assert_eq!(t.nanosecond(), 0);

pub fn from_hms_opt(hour: u32, min: u32, sec: u32) -> Option<NaiveTime>[src]

Makes a new NaiveTime from hour, minute and second.

No leap second is allowed here; use NaiveTime::from_hms_*_opt methods with a subsecond parameter instead.

Returns None on invalid hour, minute and/or second.

Example

use chrono::NaiveTime;

let from_hms_opt = NaiveTime::from_hms_opt;

assert!(from_hms_opt(0, 0, 0).is_some());
assert!(from_hms_opt(23, 59, 59).is_some());
assert!(from_hms_opt(24, 0, 0).is_none());
assert!(from_hms_opt(23, 60, 0).is_none());
assert!(from_hms_opt(23, 59, 60).is_none());

pub fn from_hms_milli(hour: u32, min: u32, sec: u32, milli: u32) -> NaiveTime[src]

Makes a new NaiveTime from hour, minute, second and millisecond.

The millisecond part can exceed 1,000 in order to represent the leap second.

Panics on invalid hour, minute, second and/or millisecond.

Example

use chrono::{NaiveTime, Timelike};

let t = NaiveTime::from_hms_milli(23, 56, 4, 12);
assert_eq!(t.hour(), 23);
assert_eq!(t.minute(), 56);
assert_eq!(t.second(), 4);
assert_eq!(t.nanosecond(), 12_000_000);

pub fn from_hms_milli_opt(
    hour: u32,
    min: u32,
    sec: u32,
    milli: u32
) -> Option<NaiveTime>
[src]

Makes a new NaiveTime from hour, minute, second and millisecond.

The millisecond part can exceed 1,000 in order to represent the leap second.

Returns None on invalid hour, minute, second and/or millisecond.

Example

use chrono::NaiveTime;

let from_hmsm_opt = NaiveTime::from_hms_milli_opt;

assert!(from_hmsm_opt(0, 0, 0, 0).is_some());
assert!(from_hmsm_opt(23, 59, 59, 999).is_some());
assert!(from_hmsm_opt(23, 59, 59, 1_999).is_some()); // a leap second after 23:59:59
assert!(from_hmsm_opt(24, 0, 0, 0).is_none());
assert!(from_hmsm_opt(23, 60, 0, 0).is_none());
assert!(from_hmsm_opt(23, 59, 60, 0).is_none());
assert!(from_hmsm_opt(23, 59, 59, 2_000).is_none());

pub fn from_hms_micro(hour: u32, min: u32, sec: u32, micro: u32) -> NaiveTime[src]

Makes a new NaiveTime from hour, minute, second and microsecond.

The microsecond part can exceed 1,000,000 in order to represent the leap second.

Panics on invalid hour, minute, second and/or microsecond.

Example

use chrono::{NaiveTime, Timelike};

let t = NaiveTime::from_hms_micro(23, 56, 4, 12_345);
assert_eq!(t.hour(), 23);
assert_eq!(t.minute(), 56);
assert_eq!(t.second(), 4);
assert_eq!(t.nanosecond(), 12_345_000);

pub fn from_hms_micro_opt(
    hour: u32,
    min: u32,
    sec: u32,
    micro: u32
) -> Option<NaiveTime>
[src]

Makes a new NaiveTime from hour, minute, second and microsecond.

The microsecond part can exceed 1,000,000 in order to represent the leap second.

Returns None on invalid hour, minute, second and/or microsecond.

Example

use chrono::NaiveTime;

let from_hmsu_opt = NaiveTime::from_hms_micro_opt;

assert!(from_hmsu_opt(0, 0, 0, 0).is_some());
assert!(from_hmsu_opt(23, 59, 59, 999_999).is_some());
assert!(from_hmsu_opt(23, 59, 59, 1_999_999).is_some()); // a leap second after 23:59:59
assert!(from_hmsu_opt(24, 0, 0, 0).is_none());
assert!(from_hmsu_opt(23, 60, 0, 0).is_none());
assert!(from_hmsu_opt(23, 59, 60, 0).is_none());
assert!(from_hmsu_opt(23, 59, 59, 2_000_000).is_none());

pub fn from_hms_nano(hour: u32, min: u32, sec: u32, nano: u32) -> NaiveTime[src]

Makes a new NaiveTime from hour, minute, second and nanosecond.

The nanosecond part can exceed 1,000,000,000 in order to represent the leap second.

Panics on invalid hour, minute, second and/or nanosecond.

Example

use chrono::{NaiveTime, Timelike};

let t = NaiveTime::from_hms_nano(23, 56, 4, 12_345_678);
assert_eq!(t.hour(), 23);
assert_eq!(t.minute(), 56);
assert_eq!(t.second(), 4);
assert_eq!(t.nanosecond(), 12_345_678);

pub fn from_hms_nano_opt(
    hour: u32,
    min: u32,
    sec: u32,
    nano: u32
) -> Option<NaiveTime>
[src]

Makes a new NaiveTime from hour, minute, second and nanosecond.

The nanosecond part can exceed 1,000,000,000 in order to represent the leap second.

Returns None on invalid hour, minute, second and/or nanosecond.

Example

use chrono::NaiveTime;

let from_hmsn_opt = NaiveTime::from_hms_nano_opt;

assert!(from_hmsn_opt(0, 0, 0, 0).is_some());
assert!(from_hmsn_opt(23, 59, 59, 999_999_999).is_some());
assert!(from_hmsn_opt(23, 59, 59, 1_999_999_999).is_some()); // a leap second after 23:59:59
assert!(from_hmsn_opt(24, 0, 0, 0).is_none());
assert!(from_hmsn_opt(23, 60, 0, 0).is_none());
assert!(from_hmsn_opt(23, 59, 60, 0).is_none());
assert!(from_hmsn_opt(23, 59, 59, 2_000_000_000).is_none());

pub fn from_num_seconds_from_midnight(secs: u32, nano: u32) -> NaiveTime[src]

Makes a new NaiveTime from the number of seconds since midnight and nanosecond.

The nanosecond part can exceed 1,000,000,000 in order to represent the leap second.

Panics on invalid number of seconds and/or nanosecond.

Example

use chrono::{NaiveTime, Timelike};

let t = NaiveTime::from_num_seconds_from_midnight(86164, 12_345_678);
assert_eq!(t.hour(), 23);
assert_eq!(t.minute(), 56);
assert_eq!(t.second(), 4);
assert_eq!(t.nanosecond(), 12_345_678);

pub fn from_num_seconds_from_midnight_opt(
    secs: u32,
    nano: u32
) -> Option<NaiveTime>
[src]

Makes a new NaiveTime from the number of seconds since midnight and nanosecond.

The nanosecond part can exceed 1,000,000,000 in order to represent the leap second.

Returns None on invalid number of seconds and/or nanosecond.

Example

use chrono::NaiveTime;

let from_nsecs_opt = NaiveTime::from_num_seconds_from_midnight_opt;

assert!(from_nsecs_opt(0, 0).is_some());
assert!(from_nsecs_opt(86399, 999_999_999).is_some());
assert!(from_nsecs_opt(86399, 1_999_999_999).is_some()); // a leap second after 23:59:59
assert!(from_nsecs_opt(86_400, 0).is_none());
assert!(from_nsecs_opt(86399, 2_000_000_000).is_none());

pub fn parse_from_str(s: &str, fmt: &str) -> Result<NaiveTime, ParseError>[src]

Parses a string with the specified format string and returns a new NaiveTime. See the format::strftime module on the supported escape sequences.

Example

use chrono::NaiveTime;

let parse_from_str = NaiveTime::parse_from_str;

assert_eq!(parse_from_str("23:56:04", "%H:%M:%S"),
           Ok(NaiveTime::from_hms(23, 56, 4)));
assert_eq!(parse_from_str("pm012345.6789", "%p%I%M%S%.f"),
           Ok(NaiveTime::from_hms_micro(13, 23, 45, 678_900)));

Date and offset is ignored for the purpose of parsing.

assert_eq!(parse_from_str("2014-5-17T12:34:56+09:30", "%Y-%m-%dT%H:%M:%S%z"),
           Ok(NaiveTime::from_hms(12, 34, 56)));

Leap seconds are correctly handled by treating any time of the form hh:mm:60 as a leap second. (This equally applies to the formatting, so the round trip is possible.)

assert_eq!(parse_from_str("08:59:60.123", "%H:%M:%S%.f"),
           Ok(NaiveTime::from_hms_milli(8, 59, 59, 1_123)));

Missing seconds are assumed to be zero, but out-of-bound times or insufficient fields are errors otherwise.

assert_eq!(parse_from_str("7:15", "%H:%M"),
           Ok(NaiveTime::from_hms(7, 15, 0)));

assert!(parse_from_str("04m33s", "%Mm%Ss").is_err());
assert!(parse_from_str("12", "%H").is_err());
assert!(parse_from_str("17:60", "%H:%M").is_err());
assert!(parse_from_str("24:00:00", "%H:%M:%S").is_err());

All parsed fields should be consistent to each other, otherwise it’s an error. Here %H is for 24-hour clocks, unlike %I, and thus can be independently determined without AM/PM.

assert!(parse_from_str("13:07 AM", "%H:%M %p").is_err());

pub fn overflowing_add_signed(&self, rhs: Duration) -> (NaiveTime, i64)[src]

Adds given Duration to the current time, and also returns the number of seconds in the integral number of days ignored from the addition. (We cannot return Duration because it is subject to overflow or underflow.)

Example

use chrono::{Duration, NaiveTime};

let from_hms = NaiveTime::from_hms;

assert_eq!(from_hms(3, 4, 5).overflowing_add_signed(Duration::hours(11)),
           (from_hms(14, 4, 5), 0));
assert_eq!(from_hms(3, 4, 5).overflowing_add_signed(Duration::hours(23)),
           (from_hms(2, 4, 5), 86_400));
assert_eq!(from_hms(3, 4, 5).overflowing_add_signed(Duration::hours(-7)),
           (from_hms(20, 4, 5), -86_400));

pub fn overflowing_sub_signed(&self, rhs: Duration) -> (NaiveTime, i64)[src]

Subtracts given Duration from the current time, and also returns the number of seconds in the integral number of days ignored from the subtraction. (We cannot return Duration because it is subject to overflow or underflow.)

Example

use chrono::{Duration, NaiveTime};

let from_hms = NaiveTime::from_hms;

assert_eq!(from_hms(3, 4, 5).overflowing_sub_signed(Duration::hours(2)),
           (from_hms(1, 4, 5), 0));
assert_eq!(from_hms(3, 4, 5).overflowing_sub_signed(Duration::hours(17)),
           (from_hms(10, 4, 5), 86_400));
assert_eq!(from_hms(3, 4, 5).overflowing_sub_signed(Duration::hours(-22)),
           (from_hms(1, 4, 5), -86_400));

pub fn signed_duration_since(self, rhs: NaiveTime) -> Duration[src]

Subtracts another NaiveTime from the current time. Returns a Duration within +/- 1 day. This does not overflow or underflow at all.

As a part of Chrono’s leap second handling, the subtraction assumes that there is no leap second ever, except when any of the NaiveTimes themselves represents a leap second in which case the assumption becomes that there are exactly one (or two) leap second(s) ever.

Example

use chrono::{Duration, NaiveTime};

let from_hmsm = NaiveTime::from_hms_milli;
let since = NaiveTime::signed_duration_since;

assert_eq!(since(from_hmsm(3, 5, 7, 900), from_hmsm(3, 5, 7, 900)),
           Duration::zero());
assert_eq!(since(from_hmsm(3, 5, 7, 900), from_hmsm(3, 5, 7, 875)),
           Duration::milliseconds(25));
assert_eq!(since(from_hmsm(3, 5, 7, 900), from_hmsm(3, 5, 6, 925)),
           Duration::milliseconds(975));
assert_eq!(since(from_hmsm(3, 5, 7, 900), from_hmsm(3, 5, 0, 900)),
           Duration::seconds(7));
assert_eq!(since(from_hmsm(3, 5, 7, 900), from_hmsm(3, 0, 7, 900)),
           Duration::seconds(5 * 60));
assert_eq!(since(from_hmsm(3, 5, 7, 900), from_hmsm(0, 5, 7, 900)),
           Duration::seconds(3 * 3600));
assert_eq!(since(from_hmsm(3, 5, 7, 900), from_hmsm(4, 5, 7, 900)),
           Duration::seconds(-3600));
assert_eq!(since(from_hmsm(3, 5, 7, 900), from_hmsm(2, 4, 6, 800)),
           Duration::seconds(3600 + 60 + 1) + Duration::milliseconds(100));

Leap seconds are handled, but the subtraction assumes that there were no other leap seconds happened.

assert_eq!(since(from_hmsm(3, 0, 59, 1_000), from_hmsm(3, 0, 59, 0)),
           Duration::seconds(1));
assert_eq!(since(from_hmsm(3, 0, 59, 1_500), from_hmsm(3, 0, 59, 0)),
           Duration::milliseconds(1500));
assert_eq!(since(from_hmsm(3, 0, 59, 1_000), from_hmsm(3, 0, 0, 0)),
           Duration::seconds(60));
assert_eq!(since(from_hmsm(3, 0, 0, 0), from_hmsm(2, 59, 59, 1_000)),
           Duration::seconds(1));
assert_eq!(since(from_hmsm(3, 0, 59, 1_000), from_hmsm(2, 59, 59, 1_000)),
           Duration::seconds(61));

pub fn format_with_items<'a, I, B>(&self, items: I) -> DelayedFormat<I> where
    I: Iterator<Item = B> + Clone,
    B: Borrow<Item<'a>>, 
[src]

Formats the time with the specified formatting items. Otherwise it is the same as the ordinary format method.

The Iterator of items should be Cloneable, since the resulting DelayedFormat value may be formatted multiple times.

Example

use chrono::NaiveTime;
use chrono::format::strftime::StrftimeItems;

let fmt = StrftimeItems::new("%H:%M:%S");
let t = NaiveTime::from_hms(23, 56, 4);
assert_eq!(t.format_with_items(fmt.clone()).to_string(), "23:56:04");
assert_eq!(t.format("%H:%M:%S").to_string(),             "23:56:04");

The resulting DelayedFormat can be formatted directly via the Display trait.

assert_eq!(format!("{}", t.format_with_items(fmt)), "23:56:04");

pub fn format(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>[src]

Formats the time with the specified format string. See the format::strftime module on the supported escape sequences.

This returns a DelayedFormat, which gets converted to a string only when actual formatting happens. You may use the to_string method to get a String, or just feed it into print! and other formatting macros. (In this way it avoids the redundant memory allocation.)

A wrong format string does not issue an error immediately. Rather, converting or formatting the DelayedFormat fails. You are recommended to immediately use DelayedFormat for this reason.

Example

use chrono::NaiveTime;

let t = NaiveTime::from_hms_nano(23, 56, 4, 12_345_678);
assert_eq!(t.format("%H:%M:%S").to_string(), "23:56:04");
assert_eq!(t.format("%H:%M:%S%.6f").to_string(), "23:56:04.012345");
assert_eq!(t.format("%-I:%M %p").to_string(), "11:56 PM");

The resulting DelayedFormat can be formatted directly via the Display trait.

assert_eq!(format!("{}", t.format("%H:%M:%S")), "23:56:04");
assert_eq!(format!("{}", t.format("%H:%M:%S%.6f")), "23:56:04.012345");
assert_eq!(format!("{}", t.format("%-I:%M %p")), "11:56 PM");

Trait Implementations

impl Add<Duration> for NaiveTime[src]

An addition of Duration to NaiveTime wraps around and never overflows or underflows. In particular the addition ignores integral number of days.

As a part of Chrono’s leap second handling, the addition assumes that there is no leap second ever, except when the NaiveTime itself represents a leap second in which case the assumption becomes that there is exactly a single leap second ever.

Example

use chrono::{Duration, NaiveTime};

let from_hmsm = NaiveTime::from_hms_milli;

assert_eq!(from_hmsm(3, 5, 7, 0) + Duration::zero(),                  from_hmsm(3, 5, 7, 0));
assert_eq!(from_hmsm(3, 5, 7, 0) + Duration::seconds(1),              from_hmsm(3, 5, 8, 0));
assert_eq!(from_hmsm(3, 5, 7, 0) + Duration::seconds(-1),             from_hmsm(3, 5, 6, 0));
assert_eq!(from_hmsm(3, 5, 7, 0) + Duration::seconds(60 + 4),         from_hmsm(3, 6, 11, 0));
assert_eq!(from_hmsm(3, 5, 7, 0) + Duration::seconds(7*60*60 - 6*60), from_hmsm(9, 59, 7, 0));
assert_eq!(from_hmsm(3, 5, 7, 0) + Duration::milliseconds(80),        from_hmsm(3, 5, 7, 80));
assert_eq!(from_hmsm(3, 5, 7, 950) + Duration::milliseconds(280),     from_hmsm(3, 5, 8, 230));
assert_eq!(from_hmsm(3, 5, 7, 950) + Duration::milliseconds(-980),    from_hmsm(3, 5, 6, 970));

The addition wraps around.

assert_eq!(from_hmsm(3, 5, 7, 0) + Duration::seconds(22*60*60), from_hmsm(1, 5, 7, 0));
assert_eq!(from_hmsm(3, 5, 7, 0) + Duration::seconds(-8*60*60), from_hmsm(19, 5, 7, 0));
assert_eq!(from_hmsm(3, 5, 7, 0) + Duration::days(800),         from_hmsm(3, 5, 7, 0));

Leap seconds are handled, but the addition assumes that it is the only leap second happened.

let leap = from_hmsm(3, 5, 59, 1_300);
assert_eq!(leap + Duration::zero(),             from_hmsm(3, 5, 59, 1_300));
assert_eq!(leap + Duration::milliseconds(-500), from_hmsm(3, 5, 59, 800));
assert_eq!(leap + Duration::milliseconds(500),  from_hmsm(3, 5, 59, 1_800));
assert_eq!(leap + Duration::milliseconds(800),  from_hmsm(3, 6, 0, 100));
assert_eq!(leap + Duration::seconds(10),        from_hmsm(3, 6, 9, 300));
assert_eq!(leap + Duration::seconds(-10),       from_hmsm(3, 5, 50, 300));
assert_eq!(leap + Duration::days(1),            from_hmsm(3, 5, 59, 300));

type Output = NaiveTime

The resulting type after applying the + operator.

pub fn add(self, rhs: Duration) -> NaiveTime[src]

Performs the + operation. Read more

impl Add<FixedOffset> for NaiveTime[src]

type Output = NaiveTime

The resulting type after applying the + operator.

pub fn add(self, rhs: FixedOffset) -> NaiveTime[src]

Performs the + operation. Read more

impl AddAssign<Duration> for NaiveTime[src]

pub fn add_assign(&mut self, rhs: Duration)[src]

Performs the += operation. Read more

impl Clone for NaiveTime[src]

pub fn clone(&self) -> NaiveTime[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for NaiveTime[src]

The Debug output of the naive time t is the same as t.format("%H:%M:%S%.f").

The string printed can be readily parsed via the parse method on str.

It should be noted that, for leap seconds not on the minute boundary, it may print a representation not distinguishable from non-leap seconds. This doesn’t matter in practice, since such leap seconds never happened. (By the time of the first leap second on 1972-06-30, every time zone offset around the world has standardized to the 5-minute alignment.)

Example

use chrono::NaiveTime;

assert_eq!(format!("{:?}", NaiveTime::from_hms(23, 56, 4)),              "23:56:04");
assert_eq!(format!("{:?}", NaiveTime::from_hms_milli(23, 56, 4, 12)),    "23:56:04.012");
assert_eq!(format!("{:?}", NaiveTime::from_hms_micro(23, 56, 4, 1234)),  "23:56:04.001234");
assert_eq!(format!("{:?}", NaiveTime::from_hms_nano(23, 56, 4, 123456)), "23:56:04.000123456");

Leap seconds may also be used.

assert_eq!(format!("{:?}", NaiveTime::from_hms_milli(6, 59, 59, 1_500)), "06:59:60.500");

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

Formats the value using the given formatter. Read more

impl<'r> Decode<'r, MySql> for NaiveTime[src]

pub fn decode(
    value: MySqlValueRef<'r>
) -> Result<NaiveTime, Box<dyn Error + 'static + Sync + Send, Global>>
[src]

Decode a new value of this type using a raw value from the database.

impl<'r> Decode<'r, Postgres> for NaiveTime[src]

pub fn decode(
    value: PgValueRef<'r>
) -> Result<NaiveTime, Box<dyn Error + 'static + Sync + Send, Global>>
[src]

Decode a new value of this type using a raw value from the database.

impl<'r> Decode<'r, Sqlite> for NaiveTime[src]

pub fn decode(
    value: SqliteValueRef<'r>
) -> Result<NaiveTime, Box<dyn Error + 'static + Sync + Send, Global>>
[src]

Decode a new value of this type using a raw value from the database.

impl Display for NaiveTime[src]

The Display output of the naive time t is the same as t.format("%H:%M:%S%.f").

The string printed can be readily parsed via the parse method on str.

It should be noted that, for leap seconds not on the minute boundary, it may print a representation not distinguishable from non-leap seconds. This doesn’t matter in practice, since such leap seconds never happened. (By the time of the first leap second on 1972-06-30, every time zone offset around the world has standardized to the 5-minute alignment.)

Example

use chrono::NaiveTime;

assert_eq!(format!("{}", NaiveTime::from_hms(23, 56, 4)),              "23:56:04");
assert_eq!(format!("{}", NaiveTime::from_hms_milli(23, 56, 4, 12)),    "23:56:04.012");
assert_eq!(format!("{}", NaiveTime::from_hms_micro(23, 56, 4, 1234)),  "23:56:04.001234");
assert_eq!(format!("{}", NaiveTime::from_hms_nano(23, 56, 4, 123456)), "23:56:04.000123456");

Leap seconds may also be used.

assert_eq!(format!("{}", NaiveTime::from_hms_milli(6, 59, 59, 1_500)), "06:59:60.500");

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

Formats the value using the given formatter. Read more

impl<'_> Encode<'_, MySql> for NaiveTime[src]

pub fn encode_by_ref(&self, buf: &mut Vec<u8, Global>) -> IsNull[src]

Writes the value of self into buf without moving self. Read more

pub fn size_hint(&self) -> usize[src]

#[must_use]
fn encode(self, buf: &mut <DB as HasArguments<'q>>::ArgumentBuffer) -> IsNull
[src]

Writes the value of self into buf in the expected format for the database.

fn produces(&self) -> Option<<DB as Database>::TypeInfo>[src]

impl<'_> Encode<'_, Postgres> for NaiveTime[src]

pub fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> IsNull[src]

Writes the value of self into buf without moving self. Read more

pub fn size_hint(&self) -> usize[src]

#[must_use]
fn encode(self, buf: &mut <DB as HasArguments<'q>>::ArgumentBuffer) -> IsNull
[src]

Writes the value of self into buf in the expected format for the database.

fn produces(&self) -> Option<<DB as Database>::TypeInfo>[src]

impl<'_> Encode<'_, Sqlite> for NaiveTime[src]

pub fn encode_by_ref(
    &self,
    buf: &mut Vec<SqliteArgumentValue<'_>, Global>
) -> IsNull
[src]

Writes the value of self into buf without moving self. Read more

#[must_use]
fn encode(self, buf: &mut <DB as HasArguments<'q>>::ArgumentBuffer) -> IsNull
[src]

Writes the value of self into buf in the expected format for the database.

fn produces(&self) -> Option<<DB as Database>::TypeInfo>[src]

fn size_hint(&self) -> usize[src]

impl FromStr for NaiveTime[src]

Parsing a str into a NaiveTime uses the same format, %H:%M:%S%.f, as in Debug and Display.

Example

use chrono::NaiveTime;

let t = NaiveTime::from_hms(23, 56, 4);
assert_eq!("23:56:04".parse::<NaiveTime>(), Ok(t));

let t = NaiveTime::from_hms_nano(23, 56, 4, 12_345_678);
assert_eq!("23:56:4.012345678".parse::<NaiveTime>(), Ok(t));

let t = NaiveTime::from_hms_nano(23, 59, 59, 1_234_567_890); // leap second
assert_eq!("23:59:60.23456789".parse::<NaiveTime>(), Ok(t));

assert!("foo".parse::<NaiveTime>().is_err());

type Err = ParseError

The associated error which can be returned from parsing.

pub fn from_str(s: &str) -> Result<NaiveTime, ParseError>[src]

Parses a string s to return a value of this type. Read more

impl Hash for NaiveTime[src]

NaiveTime can be used as a key to the hash maps (in principle).

Practically this also takes account of fractional seconds, so it is not recommended. (For the obvious reason this also distinguishes leap seconds from non-leap seconds.)

pub fn hash<H>(&self, state: &mut H) where
    H: Hasher
[src]

Feeds this value into the given Hasher. Read more

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

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

impl Ord for NaiveTime[src]

pub fn cmp(&self, other: &NaiveTime) -> Ordering[src]

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl PartialEq<NaiveTime> for NaiveTime[src]

pub fn eq(&self, other: &NaiveTime) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

pub fn ne(&self, other: &NaiveTime) -> bool[src]

This method tests for !=.

impl PartialOrd<NaiveTime> for NaiveTime[src]

pub fn partial_cmp(&self, other: &NaiveTime) -> Option<Ordering>[src]

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

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl Sub<Duration> for NaiveTime[src]

A subtraction of Duration from NaiveTime wraps around and never overflows or underflows. In particular the addition ignores integral number of days. It is the same as the addition with a negated Duration.

As a part of Chrono’s leap second handling, the addition assumes that there is no leap second ever, except when the NaiveTime itself represents a leap second in which case the assumption becomes that there is exactly a single leap second ever.

Example

use chrono::{Duration, NaiveTime};

let from_hmsm = NaiveTime::from_hms_milli;

assert_eq!(from_hmsm(3, 5, 7, 0) - Duration::zero(),                  from_hmsm(3, 5, 7, 0));
assert_eq!(from_hmsm(3, 5, 7, 0) - Duration::seconds(1),              from_hmsm(3, 5, 6, 0));
assert_eq!(from_hmsm(3, 5, 7, 0) - Duration::seconds(60 + 5),         from_hmsm(3, 4, 2, 0));
assert_eq!(from_hmsm(3, 5, 7, 0) - Duration::seconds(2*60*60 + 6*60), from_hmsm(0, 59, 7, 0));
assert_eq!(from_hmsm(3, 5, 7, 0) - Duration::milliseconds(80),        from_hmsm(3, 5, 6, 920));
assert_eq!(from_hmsm(3, 5, 7, 950) - Duration::milliseconds(280),     from_hmsm(3, 5, 7, 670));

The subtraction wraps around.

assert_eq!(from_hmsm(3, 5, 7, 0) - Duration::seconds(8*60*60), from_hmsm(19, 5, 7, 0));
assert_eq!(from_hmsm(3, 5, 7, 0) - Duration::days(800),        from_hmsm(3, 5, 7, 0));

Leap seconds are handled, but the subtraction assumes that it is the only leap second happened.

let leap = from_hmsm(3, 5, 59, 1_300);
assert_eq!(leap - Duration::zero(),            from_hmsm(3, 5, 59, 1_300));
assert_eq!(leap - Duration::milliseconds(200), from_hmsm(3, 5, 59, 1_100));
assert_eq!(leap - Duration::milliseconds(500), from_hmsm(3, 5, 59, 800));
assert_eq!(leap - Duration::seconds(60),       from_hmsm(3, 5, 0, 300));
assert_eq!(leap - Duration::days(1),           from_hmsm(3, 6, 0, 300));

type Output = NaiveTime

The resulting type after applying the - operator.

pub fn sub(self, rhs: Duration) -> NaiveTime[src]

Performs the - operation. Read more

impl Sub<FixedOffset> for NaiveTime[src]

type Output = NaiveTime

The resulting type after applying the - operator.

pub fn sub(self, rhs: FixedOffset) -> NaiveTime[src]

Performs the - operation. Read more

impl Sub<NaiveTime> for NaiveTime[src]

Subtracts another NaiveTime from the current time. Returns a Duration within +/- 1 day. This does not overflow or underflow at all.

As a part of Chrono’s leap second handling, the subtraction assumes that there is no leap second ever, except when any of the NaiveTimes themselves represents a leap second in which case the assumption becomes that there are exactly one (or two) leap second(s) ever.

The implementation is a wrapper around NaiveTime::signed_duration_since.

Example

use chrono::{Duration, NaiveTime};

let from_hmsm = NaiveTime::from_hms_milli;

assert_eq!(from_hmsm(3, 5, 7, 900) - from_hmsm(3, 5, 7, 900), Duration::zero());
assert_eq!(from_hmsm(3, 5, 7, 900) - from_hmsm(3, 5, 7, 875), Duration::milliseconds(25));
assert_eq!(from_hmsm(3, 5, 7, 900) - from_hmsm(3, 5, 6, 925), Duration::milliseconds(975));
assert_eq!(from_hmsm(3, 5, 7, 900) - from_hmsm(3, 5, 0, 900), Duration::seconds(7));
assert_eq!(from_hmsm(3, 5, 7, 900) - from_hmsm(3, 0, 7, 900), Duration::seconds(5 * 60));
assert_eq!(from_hmsm(3, 5, 7, 900) - from_hmsm(0, 5, 7, 900), Duration::seconds(3 * 3600));
assert_eq!(from_hmsm(3, 5, 7, 900) - from_hmsm(4, 5, 7, 900), Duration::seconds(-3600));
assert_eq!(from_hmsm(3, 5, 7, 900) - from_hmsm(2, 4, 6, 800),
           Duration::seconds(3600 + 60 + 1) + Duration::milliseconds(100));

Leap seconds are handled, but the subtraction assumes that there were no other leap seconds happened.

assert_eq!(from_hmsm(3, 0, 59, 1_000) - from_hmsm(3, 0, 59, 0), Duration::seconds(1));
assert_eq!(from_hmsm(3, 0, 59, 1_500) - from_hmsm(3, 0, 59, 0),
           Duration::milliseconds(1500));
assert_eq!(from_hmsm(3, 0, 59, 1_000) - from_hmsm(3, 0, 0, 0), Duration::seconds(60));
assert_eq!(from_hmsm(3, 0, 0, 0) - from_hmsm(2, 59, 59, 1_000), Duration::seconds(1));
assert_eq!(from_hmsm(3, 0, 59, 1_000) - from_hmsm(2, 59, 59, 1_000),
           Duration::seconds(61));

type Output = Duration

The resulting type after applying the - operator.

pub fn sub(self, rhs: NaiveTime) -> Duration[src]

Performs the - operation. Read more

impl SubAssign<Duration> for NaiveTime[src]

pub fn sub_assign(&mut self, rhs: Duration)[src]

Performs the -= operation. Read more

impl Timelike for NaiveTime[src]

pub fn hour(&self) -> u32[src]

Returns the hour number from 0 to 23.

Example

use chrono::{NaiveTime, Timelike};

assert_eq!(NaiveTime::from_hms(0, 0, 0).hour(), 0);
assert_eq!(NaiveTime::from_hms_nano(23, 56, 4, 12_345_678).hour(), 23);

pub fn minute(&self) -> u32[src]

Returns the minute number from 0 to 59.

Example

use chrono::{NaiveTime, Timelike};

assert_eq!(NaiveTime::from_hms(0, 0, 0).minute(), 0);
assert_eq!(NaiveTime::from_hms_nano(23, 56, 4, 12_345_678).minute(), 56);

pub fn second(&self) -> u32[src]

Returns the second number from 0 to 59.

Example

use chrono::{NaiveTime, Timelike};

assert_eq!(NaiveTime::from_hms(0, 0, 0).second(), 0);
assert_eq!(NaiveTime::from_hms_nano(23, 56, 4, 12_345_678).second(), 4);

This method never returns 60 even when it is a leap second. (Why?) Use the proper formatting method to get a human-readable representation.

let leap = NaiveTime::from_hms_milli(23, 59, 59, 1_000);
assert_eq!(leap.second(), 59);
assert_eq!(leap.format("%H:%M:%S").to_string(), "23:59:60");

pub fn nanosecond(&self) -> u32[src]

Returns the number of nanoseconds since the whole non-leap second. The range from 1,000,000,000 to 1,999,999,999 represents the leap second.

Example

use chrono::{NaiveTime, Timelike};

assert_eq!(NaiveTime::from_hms(0, 0, 0).nanosecond(), 0);
assert_eq!(NaiveTime::from_hms_nano(23, 56, 4, 12_345_678).nanosecond(), 12_345_678);

Leap seconds may have seemingly out-of-range return values. You can reduce the range with time.nanosecond() % 1_000_000_000, or use the proper formatting method to get a human-readable representation.

let leap = NaiveTime::from_hms_milli(23, 59, 59, 1_000);
assert_eq!(leap.nanosecond(), 1_000_000_000);
assert_eq!(leap.format("%H:%M:%S%.9f").to_string(), "23:59:60.000000000");

pub fn with_hour(&self, hour: u32) -> Option<NaiveTime>[src]

Makes a new NaiveTime with the hour number changed.

Returns None when the resulting NaiveTime would be invalid.

Example

use chrono::{NaiveTime, Timelike};

let dt = NaiveTime::from_hms_nano(23, 56, 4, 12_345_678);
assert_eq!(dt.with_hour(7), Some(NaiveTime::from_hms_nano(7, 56, 4, 12_345_678)));
assert_eq!(dt.with_hour(24), None);

pub fn with_minute(&self, min: u32) -> Option<NaiveTime>[src]

Makes a new NaiveTime with the minute number changed.

Returns None when the resulting NaiveTime would be invalid.

Example

use chrono::{NaiveTime, Timelike};

let dt = NaiveTime::from_hms_nano(23, 56, 4, 12_345_678);
assert_eq!(dt.with_minute(45), Some(NaiveTime::from_hms_nano(23, 45, 4, 12_345_678)));
assert_eq!(dt.with_minute(60), None);

pub fn with_second(&self, sec: u32) -> Option<NaiveTime>[src]

Makes a new NaiveTime with the second number changed.

Returns None when the resulting NaiveTime would be invalid. As with the second method, the input range is restricted to 0 through 59.

Example

use chrono::{NaiveTime, Timelike};

let dt = NaiveTime::from_hms_nano(23, 56, 4, 12_345_678);
assert_eq!(dt.with_second(17), Some(NaiveTime::from_hms_nano(23, 56, 17, 12_345_678)));
assert_eq!(dt.with_second(60), None);

pub fn with_nanosecond(&self, nano: u32) -> Option<NaiveTime>[src]

Makes a new NaiveTime with nanoseconds since the whole non-leap second changed.

Returns None when the resulting NaiveTime would be invalid. As with the nanosecond method, the input range can exceed 1,000,000,000 for leap seconds.

Example

use chrono::{NaiveTime, Timelike};

let dt = NaiveTime::from_hms_nano(23, 56, 4, 12_345_678);
assert_eq!(dt.with_nanosecond(333_333_333),
           Some(NaiveTime::from_hms_nano(23, 56, 4, 333_333_333)));
assert_eq!(dt.with_nanosecond(2_000_000_000), None);

Leap seconds can theoretically follow any whole second. The following would be a proper leap second at the time zone offset of UTC-00:03:57 (there are several historical examples comparable to this “non-sense” offset), and therefore is allowed.

assert_eq!(dt.with_nanosecond(1_333_333_333),
           Some(NaiveTime::from_hms_nano(23, 56, 4, 1_333_333_333)));

pub fn num_seconds_from_midnight(&self) -> u32[src]

Returns the number of non-leap seconds past the last midnight.

Example

use chrono::{NaiveTime, Timelike};

assert_eq!(NaiveTime::from_hms(1, 2, 3).num_seconds_from_midnight(),
           3723);
assert_eq!(NaiveTime::from_hms_nano(23, 56, 4, 12_345_678).num_seconds_from_midnight(),
           86164);
assert_eq!(NaiveTime::from_hms_milli(23, 59, 59, 1_000).num_seconds_from_midnight(),
           86399);

fn hour12(&self) -> (bool, u32)[src]

Returns the hour number from 1 to 12 with a boolean flag, which is false for AM and true for PM. Read more

impl Type<MySql> for NaiveTime[src]

pub fn type_info() -> MySqlTypeInfo[src]

Returns the canonical SQL type for this Rust type. Read more

fn compatible(ty: &<DB as Database>::TypeInfo) -> bool[src]

Determines if this Rust type is compatible with the given SQL type. Read more

impl Type<Postgres> for NaiveTime[src]

pub fn type_info() -> PgTypeInfo[src]

Returns the canonical SQL type for this Rust type. Read more

fn compatible(ty: &<DB as Database>::TypeInfo) -> bool[src]

Determines if this Rust type is compatible with the given SQL type. Read more

impl Type<Sqlite> for NaiveTime[src]

pub fn type_info() -> SqliteTypeInfo[src]

Returns the canonical SQL type for this Rust type. Read more

pub fn compatible(ty: &SqliteTypeInfo) -> bool[src]

Determines if this Rust type is compatible with the given SQL type. Read more

impl Copy for NaiveTime[src]

impl Eq for NaiveTime[src]

impl StructuralEq for NaiveTime[src]

impl StructuralPartialEq for NaiveTime[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> CallHasher for T where
    T: Hash + ?Sized

pub default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64 where
    B: BuildHasher,
    H: Hash + ?Sized

impl<T> Conv for T

fn conv<T>(self) -> T where
    Self: Into<T>, 

Converts self into T using Into<T>. Read more

impl<T> Conv for T

fn conv<T>(self) -> T where
    Self: Into<T>, 

Converts self into a target type. Read more

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

pub fn equivalent(&self, key: &K) -> bool[src]

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

impl<T> FmtForward for T

fn fmt_binary(self) -> FmtBinary<Self> where
    Self: Binary

Causes self to use its Binary implementation when Debug-formatted.

fn fmt_display(self) -> FmtDisplay<Self> where
    Self: Display

Causes self to use its Display implementation when Debug-formatted. Read more

fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
    Self: LowerExp

Causes self to use its LowerExp implementation when Debug-formatted. Read more

fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
    Self: LowerHex

Causes self to use its LowerHex implementation when Debug-formatted. Read more

fn fmt_octal(self) -> FmtOctal<Self> where
    Self: Octal

Causes self to use its Octal implementation when Debug-formatted.

fn fmt_pointer(self) -> FmtPointer<Self> where
    Self: Pointer

Causes self to use its Pointer implementation when Debug-formatted. Read more

fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
    Self: UpperExp

Causes self to use its UpperExp implementation when Debug-formatted. Read more

fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
    Self: UpperHex

Causes self to use its UpperHex implementation when Debug-formatted. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Pipe for T where
    T: ?Sized

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R

Pipes by value. This is generally the method you want to use. Read more

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R where
    R: 'a, 

Borrows self and passes that borrow into the pipe function. Read more

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
    R: 'a, 

Mutably borrows self and passes that borrow into the pipe function. Read more

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
    Self: Borrow<B>,
    R: 'a,
    B: 'a + ?Sized

Borrows self, then passes self.borrow() into the pipe function. Read more

fn pipe_borrow_mut<'a, B, R>(
    &'a mut self,
    func: impl FnOnce(&'a mut B) -> R
) -> R where
    Self: BorrowMut<B>,
    R: 'a,
    B: 'a + ?Sized

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
    Self: AsRef<U>,
    U: 'a + ?Sized,
    R: 'a, 

Borrows self, then passes self.as_ref() into the pipe function.

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
    Self: AsMut<U>,
    U: 'a + ?Sized,
    R: 'a, 

Mutably borrows self, then passes self.as_mut() into the pipe function. Read more

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
    Self: Deref<Target = T>,
    T: 'a + ?Sized,
    R: 'a, 

Borrows self, then passes self.deref() into the pipe function.

fn pipe_deref_mut<'a, T, R>(
    &'a mut self,
    func: impl FnOnce(&'a mut T) -> R
) -> R where
    Self: DerefMut<Target = T> + Deref,
    T: 'a + ?Sized,
    R: 'a, 

Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more

impl<T> Pipe for T

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R

Pipes a value into a function that cannot ordinarily be called in suffix position. Read more

impl<T> PipeAsRef for T

fn pipe_as_ref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
    Self: AsRef<T>,
    T: 'a,
    R: 'a, 

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

fn pipe_as_mut<'a, T, R>(&'a mut self, func: impl FnOnce(&'a mut T) -> R) -> R where
    Self: AsMut<T>,
    T: 'a,
    R: 'a, 

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

impl<T> PipeBorrow for T

fn pipe_borrow<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
    Self: Borrow<T>,
    T: 'a,
    R: 'a, 

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

fn pipe_borrow_mut<'a, T, R>(
    &'a mut self,
    func: impl FnOnce(&'a mut T) -> R
) -> R where
    Self: BorrowMut<T>,
    T: 'a,
    R: 'a, 

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

impl<T> PipeDeref for T

fn pipe_deref<'a, R>(&'a self, func: impl FnOnce(&'a Self::Target) -> R) -> R where
    Self: Deref,
    R: 'a, 

Pipes a dereference into a function that cannot normally be called in suffix position. Read more

fn pipe_deref_mut<'a, R>(
    &'a mut self,
    func: impl FnOnce(&'a mut Self::Target) -> R
) -> R where
    Self: DerefMut,
    R: 'a, 

Pipes a mutable dereference into a function that cannot normally be called in suffix position. Read more

impl<T> PipeRef for T

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R where
    R: 'a, 

Pipes a reference into a function that cannot ordinarily be called in suffix position. Read more

fn pipe_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
    R: 'a, 

Pipes a mutable reference into a function that cannot ordinarily be called in suffix position. Read more

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> SubsecRound for T where
    T: Add<Duration, Output = T> + Sub<Duration, Output = T> + Timelike
[src]

pub fn round_subsecs(self, digits: u16) -> T[src]

Return a copy rounded to the specified number of subsecond digits. With 9 or more digits, self is returned unmodified. Halfway values are rounded up (away from zero). Read more

pub fn trunc_subsecs(self, digits: u16) -> T[src]

Return a copy truncated to the specified number of subsecond digits. With 9 or more digits, self is returned unmodified. Read more

impl<T> Tap for T

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
    Self: Borrow<B>,
    B: ?Sized

Immutable access to the Borrow<B> of a value. Read more

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
    Self: BorrowMut<B>,
    B: ?Sized

Mutable access to the BorrowMut<B> of a value. Read more

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self where
    Self: AsRef<R>,
    R: ?Sized

Immutable access to the AsRef<R> view of a value. Read more

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
    Self: AsMut<R>,
    R: ?Sized

Mutable access to the AsMut<R> view of a value. Read more

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self where
    Self: Deref<Target = T>,
    T: ?Sized

Immutable access to the Deref::Target of a value. Read more

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self where
    Self: DerefMut<Target = T> + Deref,
    T: ?Sized

Mutable access to the Deref::Target of a value. Read more

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds. Read more

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
    Self: Borrow<B>,
    B: ?Sized

Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
    Self: BorrowMut<B>,
    B: ?Sized

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
    Self: AsRef<R>,
    R: ?Sized

Calls .tap_ref() only in debug builds, and is erased in release builds. Read more

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
    Self: AsMut<R>,
    R: ?Sized

Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self where
    Self: Deref<Target = T>,
    T: ?Sized

Calls .tap_deref() only in debug builds, and is erased in release builds. Read more

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self where
    Self: DerefMut<Target = T> + Deref,
    T: ?Sized

Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more

impl<T> Tap for T

fn tap<F, R>(self, func: F) -> Self where
    F: FnOnce(&Self) -> R, 

Provides immutable access for inspection. Read more

fn tap_dbg<F, R>(self, func: F) -> Self where
    F: FnOnce(&Self) -> R, 

Calls tap in debug builds, and does nothing in release builds.

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

Provides mutable access for modification. Read more

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

Calls tap_mut in debug builds, and does nothing in release builds.

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

fn tap_ref<F, R>(self, func: F) -> Self where
    Self: AsRef<T>,
    F: FnOnce(&T) -> R, 

Provides immutable access to the reference for inspection.

fn tap_ref_dbg<F, R>(self, func: F) -> Self where
    Self: AsRef<T>,
    F: FnOnce(&T) -> R, 

Calls tap_ref in debug builds, and does nothing in release builds.

fn tap_ref_mut<F, R>(self, func: F) -> Self where
    Self: AsMut<T>,
    F: FnOnce(&mut T) -> R, 

Provides mutable access to the reference for modification.

fn tap_ref_mut_dbg<F, R>(self, func: F) -> Self where
    Self: AsMut<T>,
    F: FnOnce(&mut T) -> R, 

Calls tap_ref_mut in debug builds, and does nothing in release builds.

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

fn tap_borrow<F, R>(self, func: F) -> Self where
    Self: Borrow<T>,
    F: FnOnce(&T) -> R, 

Provides immutable access to the borrow for inspection. Read more

fn tap_borrow_dbg<F, R>(self, func: F) -> Self where
    Self: Borrow<T>,
    F: FnOnce(&T) -> R, 

Calls tap_borrow in debug builds, and does nothing in release builds.

fn tap_borrow_mut<F, R>(self, func: F) -> Self where
    Self: BorrowMut<T>,
    F: FnOnce(&mut T) -> R, 

Provides mutable access to the borrow for modification.

fn tap_borrow_mut_dbg<F, R>(self, func: F) -> Self where
    Self: BorrowMut<T>,
    F: FnOnce(&mut T) -> R, 

Calls tap_borrow_mut in debug builds, and does nothing in release builds. Read more

impl<T> TapDeref for T

fn tap_deref<F, R>(self, func: F) -> Self where
    Self: Deref,
    F: FnOnce(&Self::Target) -> R, 

Immutably dereferences self for inspection.

fn tap_deref_dbg<F, R>(self, func: F) -> Self where
    Self: Deref,
    F: FnOnce(&Self::Target) -> R, 

Calls tap_deref in debug builds, and does nothing in release builds.

fn tap_deref_mut<F, R>(self, func: F) -> Self where
    Self: DerefMut,
    F: FnOnce(&mut Self::Target) -> R, 

Mutably dereferences self for modification.

fn tap_deref_mut_dbg<F, R>(self, func: F) -> Self where
    Self: DerefMut,
    F: FnOnce(&mut Self::Target) -> R, 

Calls tap_deref_mut in debug builds, and does nothing in release builds. Read more

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T> TryConv for T

fn try_conv<T>(self) -> Result<T, Self::Error> where
    Self: TryInto<T>, 

Attempts to convert self into T using TryInto<T>. Read more

impl<T> TryConv for T

fn try_conv<T>(self) -> Result<T, Self::Error> where
    Self: TryInto<T>, 

Attempts to convert self into a target type. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V