(s: &str, max_bytes: usize)
| 302 | /// multi-byte codepoint. Signal-safe (no allocation, no panic). |
| 303 | #[cfg(any(unix, windows))] |
| 304 | fn safe_truncate(s: &str, max_bytes: usize) -> (&str, bool) { |
| 305 | if s.len() <= max_bytes { |
| 306 | return (s, false); |
| 307 | } |
| 308 | let mut end = max_bytes; |
| 309 | while end > 0 && !s.is_char_boundary(end) { |
| 310 | end -= 1; |
| 311 | } |
| 312 | (&s[..end], true) |
| 313 | } |
| 314 | |
| 315 | /// Write a string to fd, truncating with "..." if it exceeds MAX_STRING_LENGTH. |
| 316 | /// Mirrors `_Py_DumpASCII` truncation behavior. |