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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//! This crate provides a simple way to print a string and have each letter take a
//! duration of time to be printed out.
//!
//! # Examples
//!
//! Typing out "hello" with each character taking 10 milliseconds to be printed
//!
//! ```
//! use print_typewriter::{char_duration, println_typed};
//!
//! let duration = char_duration!(default 10.ms);
//! println_typed!(duration, "hello");
//! ```
//!
//! Typing "hello world" with each word being typed instantly and each space taking 250 milliesconds
//!
//! ```
//! use print_typewriter::{char_duration, println_typed};
//!
//! let duration = char_duration!(' '->250.ms);
//! println_typed!(duration, "hello world");
//! ```
//!
//! Typing a formatted string, "hello {} world" with spaces taking 250 milliseconds, periods taking 1 second, and everything else taking 90
//!
//! ```
//! use print_typewriter::{char_duration, println_typed};
//!
//! let duration = char_duration!(default 90.ms, ' '->250.ms, '.'->1.s);
//! let beans = "beans";
//! println_typed!(duration, "hello {} world", beans);
//! ```
use ;
/// A `CharDurations` type to represent how long [`Writer::print_typed`] should take
/// to print out the inputted [`String`]
///
/// It defines how long [`Writer`] should wait after printing each character.
///
/// [`default duration`]: struct.CharDurations.html#structfield.default_duration
/// [`specific duration`]: struct.CharDurations.html#structfield.specific_duration
/// [`Writer::print_typed`]: struct.Writer.html#method.print_typed
/// # Examples
///
/// ```
/// use print_typewriter::CharDurations;
/// use std::time::Duration;
/// use std::collections::HashMap;
///
/// const two_hundred_millis: Duration = Duration::from_millis(200);
/// const one_hundred_millis: Duration = Duration::from_millis(100);
/// const fifty_millis: Duration = Duration::from_millis(50);
///
/// let per_word = CharDurations::new(
/// Duration::ZERO,
/// HashMap::from([
/// (' ', two_hundred_millis)
/// ])
/// );
/// let per_letter = CharDurations::new(
/// fifty_millis,
/// HashMap::from([
/// (' ', one_hundred_millis),
/// (',', one_hundred_millis),
/// ('.', two_hundred_millis)
/// ])
/// );
///
/// assert_eq!(*per_word.duration(' '), two_hundred_millis);
/// assert_eq!(*per_word.duration('a'), Duration::ZERO);
///
/// assert_eq!(*per_letter.duration(' '), one_hundred_millis);
/// assert_eq!(*per_letter.duration('.'), two_hundred_millis);
/// assert_eq!(*per_letter.duration('b'), fifty_millis);
/// ```
/// A `Writer` to print out given strings one letter at a time using the provided [`CharDurations`]
///
/// The writer will block the current thread after printing each character and flushing [`Stdout`]
///
/// [`Stdout`]: https://doc.rust-lang.org/1.67.0/std/io/struct.Stdout.html#method.flush
///
/// # Examples
///
/// # Examples
///
/// ```
/// use print_typewriter::{CharDurations, Writer};
/// use std::time::Duration;
/// use std::collections::HashMap;
///
/// let ten_millis = Duration::from_millis(10);
///
/// let chat_durations = CharDurations::new(ten_millis, HashMap::new());
///
/// Writer::print_typed(&chat_durations, &"hello".to_owned());
///
/// ```
;