[][src]Struct datetime_string::common::Hms6ColonStr

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

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

Implementations

impl Hms6ColonStr[src]

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

Creates a new &Hms6ColonStr from a string slice.

Examples

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

assert!(Hms6ColonStr::from_str("00:00:00").is_ok());
assert!(Hms6ColonStr::from_str("23:59:59").is_ok());
assert!(Hms6ColonStr::from_str("23:59:60").is_ok(), "Leap second is always allowed");

assert!(Hms6ColonStr::from_str("24:00:00").is_err(), "Invalid hour");
assert!(Hms6ColonStr::from_str("00:60:00").is_err(), "Invalid minute");
assert!(Hms6ColonStr::from_str("00:00:61").is_err(), "Invalid second");

pub fn from_mut_str(s: &mut str) -> Result<&mut Self, Error>[src]

Creates a new &mut Hms6ColonStr from a mutable string slice.

Examples

let mut buf = "12:34:56".to_owned();
let time = Hms6ColonStr::from_mut_str(&mut buf)?;
assert_eq!(time.as_str(), "12:34:56");

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

assert_eq!(buf, "00:34:56");

pub fn from_bytes(s: &[u8]) -> Result<&Self, Error>[src]

Creates a new &Hms6ColonStr from a byte slice.

Examples

let time = Hms6ColonStr::from_bytes(b"12:34:56")?;
assert_eq!(time.as_str(), "12:34:56");

assert!(Hms6ColonStr::from_bytes(b"00:00:00").is_ok());
assert!(Hms6ColonStr::from_bytes(b"23:59:59").is_ok());
assert!(Hms6ColonStr::from_bytes(b"23:59:60").is_ok(), "Leap second is always allowed");

assert!(Hms6ColonStr::from_bytes(b"24:00:00").is_err(), "Invalid hour");
assert!(Hms6ColonStr::from_bytes(b"00:60:00").is_err(), "Invalid minute");
assert!(Hms6ColonStr::from_bytes(b"00:00:61").is_err(), "Invalid second");

pub fn from_bytes_mut(s: &mut [u8]) -> Result<&mut Self, Error>[src]

Creates a new &mut Hms6ColonStr from a mutable byte slice.

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_eq!(&buf[..], b"00:34:56");

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 Hms6ColonStr[src]

impl AsMut<Hms6ColonStr> for Hms6ColonString[src]

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

impl AsRef<Hms6ColonStr> for Hms6ColonStr[src]

impl AsRef<Hms6ColonStr> for Hms6ColonString[src]

impl AsRef<str> for Hms6ColonStr[src]

impl Borrow<Hms6ColonStr> for Hms6ColonString[src]

impl BorrowMut<Hms6ColonStr> for Hms6ColonString[src]

impl Debug for Hms6ColonStr[src]

impl Deref for Hms6ColonStr[src]

type Target = str

The resulting type after dereferencing.

impl<'de> Deserialize<'de> for &'de Hms6ColonStr[src]

impl Display for Hms6ColonStr[src]

impl Eq for Hms6ColonStr[src]

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

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

impl<'a> From<&'a Hms6ColonStr> for &'a str[src]

impl Hash for Hms6ColonStr[src]

impl Ord for Hms6ColonStr[src]

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

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

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

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

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

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

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

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

impl PartialEq<Hms6ColonStr> for Hms6ColonStr[src]

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

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

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

impl PartialEq<Hms6ColonStr> for str[src]

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

impl PartialEq<Hms6ColonStr> for Hms6ColonString[src]

impl PartialEq<Hms6ColonString> for Hms6ColonStr[src]

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

impl PartialEq<str> for Hms6ColonStr[src]

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

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

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

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

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

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

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

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

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

impl PartialOrd<Hms6ColonStr> for Hms6ColonStr[src]

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

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

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

impl PartialOrd<Hms6ColonStr> for str[src]

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

impl PartialOrd<Hms6ColonStr> for Hms6ColonString[src]

impl PartialOrd<Hms6ColonString> for Hms6ColonStr[src]

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

impl PartialOrd<str> for Hms6ColonStr[src]

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

impl Serialize for Hms6ColonStr[src]

impl StructuralEq for Hms6ColonStr[src]

impl StructuralPartialEq for Hms6ColonStr[src]

impl ToOwned for Hms6ColonStr[src]

type Owned = Hms6ColonString

The resulting type after obtaining ownership.

impl<'a> TryFrom<&'a [u8]> for &'a Hms6ColonStr[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<&'a mut [u8]> for &'a mut Hms6ColonStr[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<&'a mut str> for &'a mut Hms6ColonStr[src]

type Error = Error

The type returned in the event of a conversion error.

impl<'a> TryFrom<&'a str> for &'a Hms6ColonStr[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> 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]