(&self, class_name: &str, vm: &VirtualMachine)
| 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); |
no test coverage detected