1pub fn create_padding(element: char, required: usize, actual: usize, minimum: usize) -> String {
2 let count = required.checked_sub(actual).unwrap_or_default().max(minimum);
3 std::iter::repeat(element).take(count).collect()
4}
5
6pub fn remove_char(string: &str, index: usize) -> String {
7 let next = index + 1;
8 format!("{}{}", &string[..index], &string[next..])
9}
10
11#[cfg(test)]
12pub mod tests {
13 use std::io;
14 use std::io::Write;
15
16 pub struct BufferWriter {
17 pub buffer: String,
18 }
19
20 impl BufferWriter {
21 pub fn new() -> Self {
22 let buffer = String::new();
23 Self { buffer }
24 }
25 }
26
27 impl Write for BufferWriter {
28 fn write(&mut self, buffer: &[u8]) -> io::Result<usize> {
29 unsafe { self.buffer.as_mut_vec().write(buffer) }
30 }
31
32 fn flush(&mut self) -> io::Result<()> {
33 Ok(())
34 }
35 }
36}