Skip to main content

Time

Struct Time 

Source
pub struct Time {
    pub hour: u8,
    pub minute: u8,
    pub second: u8,
    pub nanosecond: u32,
    /* private fields */
}
Expand description

Represents the time of day portion of a TOML datetime value.

Field ranges are validated during parsing:

  • hour: 0–23
  • minute: 0–59
  • second: 0–60 (60 is permitted for leap seconds)
  • nanosecond: 0–999999999

When seconds are omitted in the source (e.g. 12:30), second defaults to 0. Use has_seconds to distinguish this from an explicit :00.

§Examples

use toml_spanner::DateTime;

let dt: DateTime = "14:30:05.123".parse().unwrap();
let time = dt.time().unwrap();
assert_eq!(time.hour, 14);
assert_eq!(time.minute, 30);
assert_eq!(time.second, 5);
assert_eq!(time.nanosecond, 123000000);
assert_eq!(time.subsecond_precision(), 3);

Fields§

§hour: u8

Hour of the day (0–23).

§minute: u8

Minute of the hour (0–59).

§second: u8

Second of the minute (0–60).

§nanosecond: u32

Sub-second component in nanoseconds (0–999999999).

Implementations§

Source§

impl Time

Source

pub fn subsecond_precision(&self) -> u8

Returns the number of fractional-second digits present in the source.

Returns 0 when no fractional part was written (e.g. 12:30:00), and 1–9 for .1 through .123456789.

Source

pub fn has_seconds(&self) -> bool

Returns true if seconds were explicitly written in the source.

When the input omits seconds (e.g. 12:30), second is set to 0 but this method returns false.

Trait Implementations§

Source§

impl Clone for Time

Source§

fn clone(&self) -> Time

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Time

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Time

Source§

fn eq(&self, other: &Self) -> 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.
Source§

impl Copy for Time

Source§

impl Eq for Time

Auto Trait Implementations§

§

impl Freeze for Time

§

impl RefUnwindSafe for Time

§

impl Send for Time

§

impl Sync for Time

§

impl Unpin for Time

§

impl UnsafeUnpin for Time

§

impl UnwindSafe for Time

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
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> CloneToUninit for T
where T: Clone,

Source§

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

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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
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.