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

Function collection_repr

crates/vm/src/utils.rs:40–74  ·  view source on GitHub ↗
(
    class_name: Option<&str>,
    prefix: &str,
    suffix: &str,
    iter: I,
    vm: &VirtualMachine,
)

Source from the content-addressed store, hash-verified

38impl ToCString for PyUtf8Str {}
39
40pub(crate) fn collection_repr<'a, I>(
41 class_name: Option<&str>,
42 prefix: &str,
43 suffix: &str,
44 iter: I,
45 vm: &VirtualMachine,
46) -> PyResult<Wtf8Buf>
47where
48 I: core::iter::Iterator<Item = &'a PyObjectRef>,
49{
50 let mut repr = Wtf8Buf::new();
51 if let Some(name) = class_name {
52 repr.push_str(name);
53 repr.push_char('(');
54 }
55 repr.push_str(prefix);
56 {
57 let mut parts_iter = iter.map(|o| o.repr(vm));
58 let first = parts_iter
59 .next()
60 .transpose()?
61 .expect("this is not called for empty collection");
62 repr.push_wtf8(first.as_wtf8());
63 for part in parts_iter {
64 repr.push_str(", ");
65 repr.push_wtf8(part?.as_wtf8());
66 }
67 }
68 repr.push_str(suffix);
69 if class_name.is_some() {
70 repr.push_char(')');
71 }
72
73 Ok(repr)
74}

Callers 3

reprMethod · 0.85
reprMethod · 0.85
reprMethod · 0.85

Calls 8

newFunction · 0.85
push_wtf8Method · 0.80
push_strMethod · 0.45
push_charMethod · 0.45
mapMethod · 0.45
reprMethod · 0.45
nextMethod · 0.45
as_wtf8Method · 0.45

Tested by

no test coverage detected