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

Method repr_with_name

crates/vm/src/bytes_inner.rs:252–267  ·  view source on GitHub ↗
(&self, class_name: &str, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

250 }
251
252 pub fn repr_with_name(&self, class_name: &str, vm: &VirtualMachine) -> PyResult<String> {
253 const DECORATION_LEN: isize = 2 + 3; // 2 for (), 3 for b"" => bytearray(b"")
254 let escape = crate::literal::escape::AsciiEscape::new_repr(&self.elements);
255 let len = escape
256 .layout()
257 .len
258 .and_then(|len| (len as isize).checked_add(DECORATION_LEN + class_name.len() as isize))
259 .ok_or_else(|| Self::new_repr_overflow_error(vm))? as usize;
260 let mut buf = String::with_capacity(len);
261 buf.push_str(class_name);
262 buf.push('(');
263 escape.bytes_repr().write(&mut buf).unwrap();
264 buf.push(')');
265 debug_assert_eq!(buf.len(), len);
266 Ok(buf)
267 }
268
269 pub fn repr_bytes(&self, vm: &VirtualMachine) -> PyResult<String> {
270 let escape = crate::literal::escape::AsciiEscape::new_repr(&self.elements);

Callers 2

slot_strMethod · 0.80
repr_strMethod · 0.80

Calls 8

ok_or_elseMethod · 0.80
bytes_reprMethod · 0.80
layoutMethod · 0.45
lenMethod · 0.45
push_strMethod · 0.45
pushMethod · 0.45
unwrapMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected