pub enum Indent {
    Spaces(u8),
    Tabs(u8),
}

Variants§

§

Spaces(u8)

§

Tabs(u8)

Implementations§

Examples found in repository?
src/print.rs (line 471)
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
pub fn print_array<I: IntoIterator>(
	items: I,
	f: &mut fmt::Formatter,
	options: &Options,
	indent: usize,
	sizes: &[Size],
	index: &mut usize,
) -> fmt::Result
where
	I::IntoIter: ExactSizeIterator,
	I::Item: PrintWithSize,
{
	use fmt::Display;
	let size = sizes[*index];
	*index += 1;

	f.write_str("[")?;

	let items = items.into_iter();
	if items.len() == 0 {
		match size {
			Size::Expanded => {
				f.write_str("\n")?;
				options.indent.by(indent).fmt(f)?;
			}
			Size::Width(_) => Spaces(options.array_empty).fmt(f)?,
		}
	} else {
		match size {
			Size::Expanded => {
				f.write_str("\n")?;

				for (i, item) in items.enumerate() {
					if i > 0 {
						Spaces(options.array_before_comma).fmt(f)?;
						f.write_str(",\n")?
					}

					options.indent.by(indent + 1).fmt(f)?;
					item.fmt_with_size(f, options, indent + 1, sizes, index)?
				}

				f.write_str("\n")?;
				options.indent.by(indent).fmt(f)?;
			}
			Size::Width(_) => {
				Spaces(options.array_begin).fmt(f)?;
				for (i, item) in items.enumerate() {
					if i > 0 {
						Spaces(options.array_before_comma).fmt(f)?;
						f.write_str(",")?;
						Spaces(options.array_after_comma).fmt(f)?
					}

					item.fmt_with_size(f, options, indent + 1, sizes, index)?
				}
				Spaces(options.array_end).fmt(f)?
			}
		}
	}

	f.write_str("]")
}

impl<T: PrintWithSize> PrintWithSize for Vec<T> {
	#[inline(always)]
	fn fmt_with_size(
		&self,
		f: &mut fmt::Formatter,
		options: &Options,
		indent: usize,
		sizes: &[Size],
		index: &mut usize,
	) -> fmt::Result {
		print_array(self, f, options, indent, sizes, index)
	}
}

pub fn print_object<'a, V, I: IntoIterator<Item = (&'a str, V)>>(
	entries: I,
	f: &mut fmt::Formatter,
	options: &Options,
	indent: usize,
	sizes: &[Size],
	index: &mut usize,
) -> fmt::Result
where
	I::IntoIter: ExactSizeIterator,
	V: PrintWithSize,
{
	use fmt::Display;
	let size = sizes[*index];
	*index += 1;

	f.write_str("{")?;

	let entries = entries.into_iter();
	if entries.len() == 0 {
		match size {
			Size::Expanded => {
				f.write_str("\n")?;
				options.indent.by(indent).fmt(f)?;
			}
			Size::Width(_) => Spaces(options.object_empty).fmt(f)?,
		}
	} else {
		match size {
			Size::Expanded => {
				f.write_str("\n")?;

				for (i, (key, value)) in entries.enumerate() {
					if i > 0 {
						Spaces(options.object_before_comma).fmt(f)?;
						f.write_str(",\n")?
					}

					options.indent.by(indent + 1).fmt(f)?;

					string_literal(key, f)?;
					Spaces(options.object_before_colon).fmt(f)?;
					f.write_str(":")?;
					Spaces(options.object_after_colon).fmt(f)?;

					value.fmt_with_size(f, options, indent + 1, sizes, index)?
				}

				f.write_str("\n")?;
				options.indent.by(indent).fmt(f)?;
			}
			Size::Width(_) => {
				Spaces(options.object_begin).fmt(f)?;
				for (i, (key, value)) in entries.enumerate() {
					if i > 0 {
						Spaces(options.object_before_comma).fmt(f)?;
						f.write_str(",")?;
						Spaces(options.object_after_comma).fmt(f)?
					}

					string_literal(key, f)?;
					Spaces(options.object_before_colon).fmt(f)?;
					f.write_str(":")?;
					Spaces(options.object_after_colon).fmt(f)?;

					value.fmt_with_size(f, options, indent + 1, sizes, index)?
				}
				Spaces(options.object_end).fmt(f)?
			}
		}
	}

	f.write_str("}")
}

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Wraps self inside a Meta<Self, M> using the given metadata. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.