MCPcopy Index your code
hub / github.com/RustPython/RustPython / safe_truncate

Function safe_truncate

crates/stdlib/src/faulthandler.rs:304–313  ·  view source on GitHub ↗
(s: &str, max_bytes: usize)

Source from the content-addressed store, hash-verified

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.

Callers 1

dump_asciiFunction · 0.85

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected