Clock

Struct Clock 

Source
pub struct Clock<Time>
where Time: TimeLike,
{ /* private fields */ }
Expand description

Renders a clock in emoji

§Examples

#[cfg(feature = "time")]
{
  use time::Time;
  use emoji_clock_2::{Clock, Rounding};
  let clock = Clock::new(Time::from_hms(12, 29, 00).unwrap()).with_rounding(Rounding::Floor);
  assert_eq!("🕛", clock.to_string());
}
#[cfg(feature = "chrono")]
{
  use chrono::NaiveTime;
  use emoji_clock_2::{Clock, Meridiem};
  let am_clock = Clock::new(NaiveTime::from_hms_opt(9, 15, 00).unwrap()).with_meridiem(Meridiem::default());
  assert_eq!("🕤🌞", am_clock.to_string());
  let pm_clock = Clock::new(NaiveTime::from_hms_opt(21, 44, 00).unwrap()).with_meridiem(Meridiem{ am: '🌞', pm: '🌙' });
  assert_eq!("🕤🌙", pm_clock.to_string());
}

Implementations§

Source§

impl<Time> Clock<Time>
where Time: TimeLike,

Source

pub const fn new(time: Time) -> Self

Creates a new clock with round strategy and no meridiem indicators

Source

pub fn with_rounding(self, rounding: Rounding) -> Self

Sets rounding strategy (Round by default)

Source

pub fn with_meridiem(self, meridiem: Meridiem) -> Self

Enables meridiem (AM/PM) indicators (disabled by default)

Trait Implementations§

Source§

impl<Time> Clone for Clock<Time>
where Time: TimeLike + Clone,

Source§

fn clone(&self) -> Clock<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<Time> Debug for Clock<Time>
where Time: TimeLike + Debug,

Source§

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

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

impl<Time> Deref for Clock<Time>
where Time: TimeLike,

Source§

type Target = Time

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<Time> DerefMut for Clock<Time>
where Time: TimeLike,

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T> Display for Clock<T>
where T: TimeLike,

Source§

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

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

impl<Time> Copy for Clock<Time>
where Time: TimeLike + Copy,

Auto Trait Implementations§

§

impl<Time> Freeze for Clock<Time>
where Time: Freeze,

§

impl<Time> RefUnwindSafe for Clock<Time>
where Time: RefUnwindSafe,

§

impl<Time> Send for Clock<Time>
where Time: Send,

§

impl<Time> Sync for Clock<Time>
where Time: Sync,

§

impl<Time> Unpin for Clock<Time>
where Time: Unpin,

§

impl<Time> UnwindSafe for Clock<Time>
where Time: UnwindSafe,

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.