1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/// Creates a [`CharDurations`] containing the arguments.
///
/// [`char_duration`] allows [`CharDurations`]s to be defined using a method syntax while specifying if the
/// durations should be milliseconds or seconds using `.ms` or `.s` respectively.
/// There are three forms of this macro:
///
/// - Create a [`CharDurations`] with only a default duration of 20 milliseconds:
///
/// ```
/// use print_typewriter::char_duration;
/// use std::time::Duration;
/// use std::collections::HashMap;
///
/// let d = char_duration!(default 20.ms);
/// assert_eq!(d.default_duration, Duration::from_millis(20));
/// assert_eq!(d.specific_duration, HashMap::new());
/// assert_eq!(*d.duration(' '), Duration::from_millis(20));
/// assert_eq!(*d.duration('a'), Duration::from_millis(20));
/// ```
///
/// - Create a [`CharDurations`] with a default duration of 50 milliseconds, a specific duration for
/// spaces of 1 second, and another for commas with 100 milliseconds
///
/// ```
/// use print_typewriter::char_duration;
/// use std::time::Duration;
/// use std::collections::HashMap;
///
/// let d = char_duration!(default 50.ms, ' '->1.s, ','->100.ms);
/// assert_eq!(d.default_duration, Duration::from_millis(50));
/// assert_eq!(d.specific_duration, HashMap::from([(' ', Duration::from_secs(1)), (',', Duration::from_millis(100))]));
/// assert_eq!(*d.duration(' '), Duration::from_secs(1));
/// assert_eq!(*d.duration(','), Duration::from_millis(100));
/// assert_eq!(*d.duration('a'), Duration::from_millis(50));
/// ```
/// - Create a [`CharDurations`] with a specific duration for spaces of 1 second
///
/// ```
/// use print_typewriter::char_duration;
/// use std::time::Duration;
/// use std::collections::HashMap;
///
/// let d = char_duration!(' '->1.s);
/// assert_eq!(d.default_duration, Duration::ZERO);
/// assert_eq!(d.specific_duration, HashMap::from([(' ', Duration::from_secs(1))]));
/// assert_eq!(*d.duration(' '), Duration::from_secs(1));
/// assert_eq!(*d.duration('a'), Duration::ZERO);
/// ```
///
/// [`CharDurations`]: crate::CharDurations
/// [`char_duration`]: crate::char_duration
///
/// Prints a formatted string using the provided [`CharDurations`]
/// Uses [`Writer::print_typed`] to print to the standard output one character at a time, with a newline.
///
/// # Examples
///
/// - Printing "hello world" one word at a time
///
/// ```
/// use print_typewriter::{char_duration, println_typed};
///
/// let duration = char_duration!(' '->150.ms);
/// println_typed!(duration, "hello world");
/// ```
///
/// - Printing a formatted string, one character at a time
///
/// ```
/// use print_typewriter::{char_duration, println_typed};
///
/// let example_variable = "beans";
/// let duration = char_duration!(default 50.ms);
/// println_typed!(duration, "hello {} world", example_variable);
/// ```
///
/// [`Writer::print_typed`]: struct.Writer.html#method.print_typed
/// [`CharDurations`]: crate::CharDurations
///