[][src]Struct datetime_string::common::Hms6ColonString

#[repr(transparent)]pub struct Hms6ColonString(_);

Owned string for a time in %H:%M:%S (hh:mm:ss) format, such as 01:23:45.

This is also an RFC 3339 partial-time string without secfrac part.

This is a fixed length string, and implements Copy trait.

To create a value of this type, use str::parse method or std::convert::TryFrom trait, or convert from &Hms6ColonStr.

Examples

use datetime_string::common::Hms6ColonStr;
use std::convert::TryFrom;

let try_from = Hms6ColonString::try_from("12:34:56")?;

let parse = "12:34:56".parse::<Hms6ColonString>()?;
let parse2: Hms6ColonString = "12:34:56".parse()?;

let to_owned = Hms6ColonStr::from_str("12:34:56")?.to_owned();
let into: Hms6ColonString = Hms6ColonStr::from_str("12:34:56")?.into();

Implementations

impl Hms6ColonString[src]

pub fn from_hms(hour: u8, minute: u8, second: u8) -> Result<Self, Error>[src]

Creates a new Hms6ColonString from the given time.

Examples

let time = Hms6ColonString::from_hms(12, 34, 56)?;
assert_eq!(time.as_str(), "12:34:56");

assert!(Hms6ColonString::from_hms(0, 0, 61).is_err(), "00:00:61 is invaild time");

#[must_use]pub fn as_deref(&self) -> &Hms6ColonStr[src]

Returns a &Hms6ColonStr for the string.

Examples

use datetime_string::common::Hms6ColonStr;
let time = "12:34:56".parse::<Hms6ColonString>()?;

// Usually you don't need to call `as_deref()` explicitly, because
// `Deref<Target = Hms6ColonStr>` trait is implemented.
let _: &Hms6ColonStr = time.as_deref();

#[must_use]pub fn as_deref_mut(&mut self) -> &mut Hms6ColonStr[src]

Returns a &mut Hms6ColonStr for the string.

Examples

use datetime_string::common::Hms6ColonStr;
let mut time = "12:34:56".parse::<Hms6ColonString>()?;

// Usually you don't need to call `as_deref_mut()` explicitly, because
// `DerefMut` trait is implemented.
let _: &mut Hms6ColonStr = time.as_deref_mut();

Methods from Deref<Target = Hms6ColonStr>

pub fn assign(&mut self, v: &Self)[src]

Assigns the given value.

Examples

let mut buf: [u8; 8] = *b"12:34:56";
let time = Hms6ColonStr::from_bytes_mut(&mut buf[..])?;
assert_eq!(time.as_str(), "12:34:56");

let newtime = Hms6ColonStr::from_str("01:01:01")?;

time.assign(newtime);
assert_eq!(time.as_str(), "01:01:01");
assert_eq!(buf, *b"01:01:01");

#[must_use]pub fn as_str(&self) -> &str[src]

Returns a string slice.

Examples

let time = Hms6ColonStr::from_str("12:34:56")?;

assert_eq!(time.as_str(), "12:34:56");

#[must_use]pub fn as_bytes(&self) -> &[u8][src]

Returns a byte slice.

If you want to use indexed access, prefer as_bytes_fixed_len.

Examples

let time = Hms6ColonStr::from_bytes(b"12:34:56")?;

assert_eq!(time.as_bytes(), b"12:34:56");

#[must_use]pub fn as_bytes_fixed_len(&self) -> &[u8; 8][src]

Returns a fixed length byte slice.

Examples

let time = Hms6ColonStr::from_str("12:34:56")?;

let fixed_len: &[u8; 8] = time.as_bytes_fixed_len();
assert_eq!(fixed_len, b"12:34:56");

#[must_use]pub fn hour_str(&self) -> &str[src]

Returns the hour as a string slice.

Examples

let time = Hms6ColonStr::from_str("12:34:56")?;

assert_eq!(time.hour_str(), "12");

#[must_use]pub fn hour_bytes_fixed_len(&self) -> &[u8; 2][src]

Returns the hour as a fixed length byte slice.

Examples

let time = Hms6ColonStr::from_str("12:34:56")?;

let hour_fixed_len: &[u8; 2] = time.hour_bytes_fixed_len();
assert_eq!(hour_fixed_len, b"12");

#[must_use]pub fn hour(&self) -> u8[src]

Returns the hour as an integer.

Examples

let time = Hms6ColonStr::from_str("12:34:56")?;

assert_eq!(time.hour(), 12);

#[must_use]pub fn minute_str(&self) -> &str[src]

Returns the minute as a string slice.

Examples

let time = Hms6ColonStr::from_str("12:34:56")?;

assert_eq!(time.minute_str(), "34");

#[must_use]pub fn minute_bytes_fixed_len(&self) -> &[u8; 2][src]

Returns the minute as a fixed length byte slice.

Examples

let time = Hms6ColonStr::from_str("12:34:56")?;

let minute_fixed_len: &[u8; 2] = time.minute_bytes_fixed_len();
assert_eq!(minute_fixed_len, b"34");

#[must_use]pub fn minute(&self) -> u8[src]

Returns the minute as an integer.

Examples

let time = Hms6ColonStr::from_str("12:34:56")?;

assert_eq!(time.minute(), 34);

#[must_use]pub fn second_str(&self) -> &str[src]

Returns the second as a string slice.

Examples

let time = Hms6ColonStr::from_str("12:34:56")?;

assert_eq!(time.second_str(), "56");

#[must_use]pub fn second_bytes_fixed_len(&self) -> &[u8; 2][src]

Returns the second as a fixed length byte slice.

Examples

let time = Hms6ColonStr::from_str("12:34:56")?;

let second_fixed_len: &[u8; 2] = time.second_bytes_fixed_len();
assert_eq!(second_fixed_len, b"56");

#[must_use]pub fn second(&self) -> u8[src]

Returns the second as an integer.

Examples

let time = Hms6ColonStr::from_str("12:34:56")?;

assert_eq!(time.second(), 56);

pub fn set_hour(&mut self, hour: u8) -> Result<(), Error>[src]

Sets the given hour value to the string.

Failures

  • Fails if the time after modification is invalid.

Examples

let mut buf: [u8; 8] = *b"12:34:56";
let time = Hms6ColonStr::from_bytes_mut(&mut buf[..])?;
assert_eq!(time.as_str(), "12:34:56");

time.set_hour(0)?;
assert_eq!(time.as_str(), "00:34:56");

assert!(time.set_hour(24).is_err(), "24:34:56 is invalid");

pub fn set_minute(&mut self, minute: u8) -> Result<(), Error>[src]

Sets the given minute value to the string.

Failures

  • Fails if the time after modification is invalid.

Examples

let mut buf: [u8; 8] = *b"12:34:56";
let time = Hms6ColonStr::from_bytes_mut(&mut buf[..])?;
assert_eq!(time.as_str(), "12:34:56");

time.set_minute(0)?;
assert_eq!(time.as_str(), "12:00:56");

assert!(time.set_minute(60).is_err(), "24:60:56 is invalid");

pub fn set_second(&mut self, second: u8) -> Result<(), Error>[src]

Sets the given second value to the string.

Failures

  • Fails if the time after modification is invalid.

Examples

let mut buf: [u8; 8] = *b"12:34:56";
let time = Hms6ColonStr::from_bytes_mut(&mut buf[..])?;
assert_eq!(time.as_str(), "12:34:56");

time.set_second(0)?;
assert_eq!(time.as_str(), "12:34:00");

assert!(time.set_second(61).is_err(), "24:34:61 is invalid");

pub fn set_hour_minute(&mut self, hour: u8, minute: u8) -> Result<(), Error>[src]

Sets the given hour and minute values to the string.

Failures

  • Fails if the time after modification is invalid.

Examples

let mut buf: [u8; 8] = *b"12:34:56";
let time = Hms6ColonStr::from_bytes_mut(&mut buf[..])?;
assert_eq!(time.as_str(), "12:34:56");

time.set_hour_minute(21, 10)?;
assert_eq!(time.as_str(), "21:10:56");

assert!(time.set_hour_minute(23, 60).is_err(), "23:60:56 is invalid");

pub fn set_minute_second(&mut self, minute: u8, second: u8) -> Result<(), Error>[src]

Sets the given minute and second values to the string.

Failures

  • Fails if the time after modification is invalid.

Examples

let mut buf: [u8; 8] = *b"12:34:56";
let time = Hms6ColonStr::from_bytes_mut(&mut buf[..])?;
assert_eq!(time.as_str(), "12:34:56");

time.set_minute_second(54, 32)?;
assert_eq!(time.as_str(), "12:54:32");

assert!(time.set_minute_second(60, 59).is_err(), "12:60:59 is invalid");

pub fn set_time(
    &mut self,
    hour: u8,
    minute: u8,
    second: u8
) -> Result<(), Error>
[src]

Sets the given hour, minute, and second values to the string.

Failures

  • Fails if the time after modification is invalid.

Examples

let mut buf: [u8; 8] = *b"12:34:56";
let time = Hms6ColonStr::from_bytes_mut(&mut buf[..])?;
assert_eq!(time.as_str(), "12:34:56");

time.set_time(23, 12, 1)?;
assert_eq!(time.as_str(), "23:12:01");

assert!(time.set_time(24, 0, 0).is_err(), "24:00:00 is invalid");

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

Retruns the seconds from the start of the day.

Example

let time = Hms6ColonStr::from_str("12:34:56")?;
assert_eq!(time.to_seconds(), 12 * 60 * 60 + 34 * 60 + 56);

let zero = Hms6ColonStr::from_str("00:00:00")?;
assert_eq!(zero.to_seconds(), 0);

let last = Hms6ColonStr::from_str("23:59:59")?;
assert_eq!(last.to_seconds(), 24 * 60 * 60 - 1);

let last_leap = Hms6ColonStr::from_str("23:59:60")?;
assert_eq!(last_leap.to_seconds(), 24 * 60 * 60);

Trait Implementations

impl AsMut<Hms6ColonStr> for Hms6ColonString[src]

impl AsRef<[u8]> for Hms6ColonString[src]

impl AsRef<Hms6ColonStr> for Hms6ColonString[src]

impl AsRef<str> for Hms6ColonString[src]

impl Borrow<Hms6ColonStr> for Hms6ColonString[src]

impl BorrowMut<Hms6ColonStr> for Hms6ColonString[src]

impl Clone for Hms6ColonString[src]

impl Copy for Hms6ColonString[src]

impl Debug for Hms6ColonString[src]

impl Deref for Hms6ColonString[src]

type Target = Hms6ColonStr

The resulting type after dereferencing.

impl DerefMut for Hms6ColonString[src]

impl<'de> Deserialize<'de> for Hms6ColonString[src]

impl Display for Hms6ColonString[src]

impl Eq for Hms6ColonString[src]

impl<'_> From<&'_ Hms6ColonStr> for Hms6ColonString[src]

impl<'_> From<&'_ NaiveTime> for Hms6ColonString[src]

impl From<Hms6ColonString> for Vec<u8>[src]

impl From<Hms6ColonString> for String[src]

impl FromStr for Hms6ColonString[src]

type Err = Error

The associated error which can be returned from parsing.

impl Hash for Hms6ColonString[src]

impl Ord for Hms6ColonString[src]

impl<'_> PartialEq<&'_ [u8]> for Hms6ColonString[src]

impl<'_> PartialEq<&'_ Hms6ColonStr> for Hms6ColonString[src]

impl<'_> PartialEq<&'_ Hms6ColonString> for Hms6ColonString[src]

impl<'_> PartialEq<&'_ Hms6ColonString> for str[src]

impl<'_> PartialEq<&'_ Hms6ColonString> for [u8][src]

impl<'_> PartialEq<&'_ str> for Hms6ColonString[src]

impl PartialEq<[u8]> for Hms6ColonString[src]

impl<'_> PartialEq<[u8]> for &'_ Hms6ColonString[src]

impl PartialEq<Hms6ColonStr> for Hms6ColonString[src]

impl PartialEq<Hms6ColonString> for Hms6ColonString[src]

impl<'_> PartialEq<Hms6ColonString> for &'_ Hms6ColonString[src]

impl PartialEq<Hms6ColonString> for Hms6ColonStr[src]

impl<'_> PartialEq<Hms6ColonString> for &'_ Hms6ColonStr[src]

impl PartialEq<Hms6ColonString> for str[src]

impl<'_> PartialEq<Hms6ColonString> for &'_ str[src]

impl PartialEq<Hms6ColonString> for [u8][src]

impl<'_> PartialEq<Hms6ColonString> for &'_ [u8][src]

impl PartialEq<str> for Hms6ColonString[src]

impl<'_> PartialEq<str> for &'_ Hms6ColonString[src]

impl<'_> PartialOrd<&'_ [u8]> for Hms6ColonString[src]

impl<'_> PartialOrd<&'_ Hms6ColonStr> for Hms6ColonString[src]

impl<'_> PartialOrd<&'_ Hms6ColonString> for Hms6ColonString[src]

impl<'_> PartialOrd<&'_ Hms6ColonString> for str[src]

impl<'_> PartialOrd<&'_ Hms6ColonString> for [u8][src]

impl<'_> PartialOrd<&'_ str> for Hms6ColonString[src]

impl PartialOrd<[u8]> for Hms6ColonString[src]

impl<'_> PartialOrd<[u8]> for &'_ Hms6ColonString[src]

impl PartialOrd<Hms6ColonStr> for Hms6ColonString[src]

impl PartialOrd<Hms6ColonString> for Hms6ColonString[src]

impl<'_> PartialOrd<Hms6ColonString> for &'_ Hms6ColonString[src]

impl PartialOrd<Hms6ColonString> for Hms6ColonStr[src]

impl<'_> PartialOrd<Hms6ColonString> for &'_ Hms6ColonStr[src]

impl PartialOrd<Hms6ColonString> for str[src]

impl<'_> PartialOrd<Hms6ColonString> for &'_ str[src]

impl PartialOrd<Hms6ColonString> for [u8][src]

impl<'_> PartialOrd<Hms6ColonString> for &'_ [u8][src]

impl PartialOrd<str> for Hms6ColonString[src]

impl<'_> PartialOrd<str> for &'_ Hms6ColonString[src]

impl Serialize for Hms6ColonString[src]

impl StructuralEq for Hms6ColonString[src]

impl StructuralPartialEq for Hms6ColonString[src]

impl<'_> TryFrom<&'_ [u8]> for Hms6ColonString[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'_> TryFrom<&'_ str> for Hms6ColonString[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<[u8; 8]> for Hms6ColonString[src]

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

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

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

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

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

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

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

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

type Owned = T

The resulting type after obtaining ownership.

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

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.

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.