MCPcopy Create free account
hub / github.com/SeaQL/FireDBG.for.Rust / fmt

Method fmt

protocol/src/value.rs:285–509  ·  view source on GitHub ↗

Pretty print `RValue` in a Rust-like syntax. Using `{:#}` would expand to multiple lines. Similar to `std::fmt::Debug`, but the goal is to make the format string almost-compile.

(&self, f: &mut std::fmt::Formatter<'_>)

Source from the content-addressed store, hash-verified

283 ///
284 /// Similar to `std::fmt::Debug`, but the goal is to make the format string almost-compile.
285 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
286 let pretty = f.alternate();
287 let width = f.width().unwrap_or_default();
288 match self {
289 Self::Unit => write!(f, "()")?,
290 Self::Prim(v) => {
291 if pretty {
292 write!(f, "{:#}", v)?
293 } else {
294 write!(f, "{}", v)?
295 }
296 }
297 Self::Bytes { typename, value } => {
298 if typename.starts_with('&') {
299 write!(f, "&")?;
300 }
301 print_bytes(f, &value)?;
302 }
303 Self::Ref {
304 typename, value, ..
305 } => {
306 let b = match *typename {
307 RefType::Ref => {
308 write!(f, "&")?;
309 ""
310 }
311 RefType::Ptr => {
312 write!(f, "*")?;
313 ""
314 }
315 RefType::Box => {
316 write!(f, "alloc::boxed::Box::new(")?;
317 ")"
318 }
319 };
320 if pretty {
321 write!(f, "{value:#width$}", width = width)?;
322 } else {
323 write!(f, "{value}")?;
324 }
325 write!(f, "{}", b)?;
326 }
327 Self::DynRef {
328 typename, value, ..
329 } => {
330 if typename.starts_with("&dyn ") {
331 write!(f, "{} ", typename)?;
332 } else {
333 write!(
334 f,
335 "{}::new(",
336 typename.replacen("alloc::boxed::Box<", "alloc::boxed::Box::<", 1)
337 )?;
338 }
339 if pretty {
340 write!(f, "{value:#width$}", width = width)?;
341 } else {
342 write!(f, "{value}")?;

Callers

nothing calls this directly

Calls 8

print_bytesFunction · 0.85
print_os_stringFunction · 0.85
print_hashmapFunction · 0.85
print_structFunction · 0.85
print_arr_itemsFunction · 0.85
nextMethod · 0.80
as_strMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected