1use rand::Rng;
2
3pub fn truncate_output(output: &str) -> String {
4 const MAX_OUTPUT_LENGTH: usize = 4000;
5 if output.len() > MAX_OUTPUT_LENGTH {
7 let offset = MAX_OUTPUT_LENGTH / 2;
8 let start = output
9 .char_indices()
10 .nth(offset)
11 .map(|(i, _)| i)
12 .unwrap_or(output.len());
13 let end = output
14 .char_indices()
15 .rev()
16 .nth(offset)
17 .map(|(i, _)| i)
18 .unwrap_or(0);
19
20 return format!("{}\n...truncated...\n{}", &output[..start], &output[end..]);
21 }
22
23 output.to_string()
24}
25
26pub fn generate_simple_id(length: usize) -> String {
27 const CHARS: &[u8] = b"abcdefghijklmnopqrstuvwxyz0123456789";
28 let mut rng = rand::rng();
29
30 (0..length)
31 .map(|_| {
32 let idx = rng.random_range(0..CHARS.len());
33 CHARS[idx] as char
34 })
35 .collect()
36}