Crate morseclock

Source
Expand description

§morseclock - Yet another not-so-intuitive clock

morseclock allows you to generate a clock visualization inspired by this hackaday post

§Usage example

use morseclock::{Clock, Format, MorseExt};

// Hour must be in the range [0, 23)
let hour = 16.try_into().unwrap();
// Minute must be in the range [0, 59)
let minute = 47.try_into().unwrap();

let clock = Clock::new(hour, minute, Format::Hour12);

let time: String = clock
    .into_iter()
    .morse()
    .collect();

assert_eq!(time, "--.=----")

§How to read the “morsecode”

The mapping generated by the MorseExt iterator extension trait can be interpreted as follows

The string "--.=----" represents the time 4:47.
The character '=' separates the hour-hand from the minute-hand.

On the hour-hand a single '-' stands for a increment of of 3 hours (a quarter rotation of the hand), starting at the 0 o’clock position.
A single '.' stands for an increment of 1 hour.

On the minute-hand, a single '-' stands for a increment of 15 minutes (a quarter rotation of the hand), starting at the 0 o’clock position. A single '.' stands for an increment of 5 minutes.

§Some time examples on the 12 hour clock

00:00 is -=-
03:00 is --=-
06:00 is ---=-
21:40 is 09:40 is ----=---..

All minutes are rounded to 5 minutes, therefore the str representations of the following times are equal

00:00 is 00:01 is .. is 00:04

Structs§

Clock
A Clock which can produce a morse-like sequence of dits and dashes
ClockIter
An iterator over a Clock which produces a series of Symbols
Hand
A clock hand
HandIter
An iterator over a Hand which produces a series of Symbols
Hour
Hour marker struct for Hand
Minute
Minute marker struct for Hand
Morse
An iterator adapter which produces a series of morsecode-like symbols

Enums§

Error
A collection of errors which can happen
Format
The output format of the clock, either 12 or 24 hours
Symbol
The symbols used to describe a time

Traits§

ClockHand
A trait describing the properties of a clock hand
MorseExt
An extension trait for iterators which yield Symbols