| 38 | impl ToCString for PyUtf8Str {} |
| 39 | |
| 40 | pub(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> |
| 47 | where |
| 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 | } |