runtime contract enforcement (#6)

This commit is contained in:
Hari 2026-03-25 22:00:16 -04:00 committed by GitHub
parent 61f4738311
commit 543d41c3a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 958 additions and 157 deletions

View file

@ -88,9 +88,21 @@ impl std::fmt::Display for WindowInfo {
#[allow(dead_code)]
fn truncate(s: &str, max: usize) -> String {
if s.len() <= max {
if s.chars().count() <= max {
s.to_string()
} else {
format!("{}...", &s[..max - 3])
let truncated: String = s.chars().take(max.saturating_sub(3)).collect();
format!("{truncated}...")
}
}
#[cfg(test)]
mod tests {
use super::truncate;
#[test]
fn truncate_is_char_safe() {
let input = format!("fire{}fox", '\u{00E9}');
assert_eq!(truncate(&input, 7), "fire...");
}
}