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

Interface Escape

crates/literal/src/escape.rs:47–69  ·  view source on GitHub ↗

Represents string types that can be escape-printed. # Safety `source_len` and `layout` must be accurate, and `layout.len` must not be equal to `Some(source_len)` if the string contains non-printable characters.

Source from the content-addressed store, hash-verified

45/// `source_len` and `layout` must be accurate, and `layout.len` must not be equal
46/// to `Some(source_len)` if the string contains non-printable characters.
47pub unsafe trait Escape {
48 fn source_len(&self) -> usize;
49 fn layout(&self) -> &EscapeLayout;
50 fn changed(&self) -> bool {
51 self.layout().len != Some(self.source_len())
52 }
53
54 /// Write the body of the string directly to the formatter.
55 ///
56 /// # Safety
57 ///
58 /// This string must only contain printable characters.
59 unsafe fn write_source(&self, formatter: &mut impl core::fmt::Write) -> core::fmt::Result;
60 fn write_body_slow(&self, formatter: &mut impl core::fmt::Write) -> core::fmt::Result;
61 fn write_body(&self, formatter: &mut impl core::fmt::Write) -> core::fmt::Result {
62 if self.changed() {
63 self.write_body_slow(formatter)
64 } else {
65 // SAFETY: verified the string contains only printable characters.
66 unsafe { self.write_source(formatter) }
67 }
68 }
69}
70
71/// Returns the outer quotes to use and the number of quotes that need to be
72/// escaped.

Callers 1

parse_escaped_charMethod · 0.85

Implementers 1

escape.rscrates/literal/src/escape.rs

Calls

no outgoing calls

Tested by

no test coverage detected