| 1 |
//! Methods for displaying [`Inspectable`]s. |
| 2 |
//! |
| 3 |
//! Refer to the [documentation here][crate::inspect#displaying--outputting]. |
| 4 |
|
| 5 |
use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::{Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#, Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#}; |
| 6 |
|
| 7 |
use craterust-analyzer cargo bendy 0.6.1 crate/::inspectrust-analyzer cargo bendy 0.6.1 inspect/::*; |
| 8 |
|
| 9 |
impl<'a> Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Inspectablerust-analyzer cargo bendy 0.6.1 inspect/Inspectable#<'a> { |
| 10 |
fn fmtrust-analyzer cargo bendy 0.6.1 inspect/display/impl#[`Inspectable<'a>`][Display]fmt().(&self, f: &mut corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 11 |
match self { |
| 12 |
Inspectablerust-analyzer cargo bendy 0.6.1 inspect/Inspectable#::Stringrust-analyzer cargo bendy 0.6.1 inspect/Inspectable#String#(x) => Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#::fmtrust-analyzer cargo bendy 0.6.1 inspect/display/impl#[`InString<'a>`][Display]fmt().(x, f), |
| 13 |
Inspectablerust-analyzer cargo bendy 0.6.1 inspect/Inspectable#::Dictrust-analyzer cargo bendy 0.6.1 inspect/Inspectable#Dict#(x) => Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#::fmtrust-analyzer cargo bendy 0.6.1 inspect/display/impl#[`InDict<'a>`][Display]fmt().(x, f), |
| 14 |
Inspectablerust-analyzer cargo bendy 0.6.1 inspect/Inspectable#::Listrust-analyzer cargo bendy 0.6.1 inspect/Inspectable#List#(x) => Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#::fmtrust-analyzer cargo bendy 0.6.1 inspect/display/impl#[`InList<'a>`][Display]fmt().(x, f), |
| 15 |
Inspectablerust-analyzer cargo bendy 0.6.1 inspect/Inspectable#::Intrust-analyzer cargo bendy 0.6.1 inspect/Inspectable#Int#(x) => Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#::fmtrust-analyzer cargo bendy 0.6.1 inspect/display/impl#[`InInt<'a>`][Display]fmt().(x, f), |
| 16 |
Inspectablerust-analyzer cargo bendy 0.6.1 inspect/Inspectable#::Rawrust-analyzer cargo bendy 0.6.1 inspect/Inspectable#Raw#(x) => { |
| 17 |
for b in x.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 18 |
writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "\\x{b:02X}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 19 |
} |
| 20 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 21 |
}, |
| 22 |
} |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
impl<'a> Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for InStringrust-analyzer cargo bendy 0.6.1 inspect/InString#<'a> { |
| 27 |
fn fmtrust-analyzer cargo bendy 0.6.1 inspect/display/impl#[`InString<'a>`][Display]fmt().(&self, f: &mut corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 28 |
let bytes = self.contentrust-analyzer cargo bendy 0.6.1 inspect/impl#[`InString<'ser>`]content().(); |
| 29 |
let all_printable = bytes.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]all().(|b| is_printable_byterust-analyzer cargo bendy 0.6.1 inspect/display/is_printable_byte().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().b)); |
| 30 |
writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}:", self.lenrust-analyzer cargo bendy 0.6.1 inspect/impl#[`InString<'ser>`]len().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 31 |
if all_printable { |
| 32 |
for &b in bytes.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 33 |
let c = char::from_u32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]from_u32().(b as u32).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Already ensured all chars are printable"); |
| 34 |
f.write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'_>`][Write]write_char().(c)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 35 |
} |
| 36 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 37 |
} else { |
| 38 |
for b in bytes.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 39 |
writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "\\x{b:02X}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 40 |
} |
| 41 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
impl<'a> Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for InIntrust-analyzer cargo bendy 0.6.1 inspect/InInt#<'a> { |
| 47 |
fn fmtrust-analyzer cargo bendy 0.6.1 inspect/display/impl#[`InInt<'a>`][Display]fmt().(&self, f: &mut corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 48 |
f.write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'_>`][Write]write_char().('i')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 49 |
f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(&self.bytesrust-analyzer cargo bendy 0.6.1 inspect/InInt#bytes.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 50 |
f.write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'_>`][Write]write_char().('e') |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
impl<'a> Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for InDictrust-analyzer cargo bendy 0.6.1 inspect/InDict#<'a> { |
| 55 |
fn fmtrust-analyzer cargo bendy 0.6.1 inspect/display/impl#[`InDict<'a>`][Display]fmt().(&self, f: &mut corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 56 |
f.write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'_>`][Write]write_char().('d')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 57 |
for InDictEntryrust-analyzer cargo bendy 0.6.1 inspect/InDictEntry# { keyrust-analyzer cargo bendy 0.6.1 inspect/InDictEntry#key., valuerust-analyzer cargo bendy 0.6.1 inspect/InDictEntry#value. } in self.itemsrust-analyzer cargo bendy 0.6.1 inspect/InDict#items..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 58 |
Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#::fmtrust-analyzer cargo bendy 0.6.1 inspect/display/impl#[`Inspectable<'a>`][Display]fmt().(key, f)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 59 |
Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#::fmtrust-analyzer cargo bendy 0.6.1 inspect/display/impl#[`Inspectable<'a>`][Display]fmt().(value, f)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 60 |
} |
| 61 |
f.write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'_>`][Write]write_char().('e') |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
impl<'a> Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for InListrust-analyzer cargo bendy 0.6.1 inspect/InList#<'a> { |
| 66 |
fn fmtrust-analyzer cargo bendy 0.6.1 inspect/display/impl#[`InList<'a>`][Display]fmt().(&self, f: &mut corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 67 |
f.write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'_>`][Write]write_char().('l')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 68 |
for inspectable in self.itemsrust-analyzer cargo bendy 0.6.1 inspect/InList#items..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 69 |
Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#::fmtrust-analyzer cargo bendy 0.6.1 inspect/display/impl#[`Inspectable<'a>`][Display]fmt().(inspectable, f)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 70 |
} |
| 71 |
f.write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'_>`][Write]write_char().('e') |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
impl<'a> Inspectablerust-analyzer cargo bendy 0.6.1 inspect/Inspectable#<'a> { |
| 76 |
/// Provides a [`String`] of pretty-printed bencode in a format |
| 77 |
/// suitable for copy-pasting as a Rust string literal. |
| 78 |
/// |
| 79 |
/// # Example |
| 80 |
/// |
| 81 |
/// ``` |
| 82 |
/// # use bendy::inspect::*; |
| 83 |
/// let i = inspect(b"li0ei1ee"); |
| 84 |
/// let lit = i.as_rust_string_literal(); |
| 85 |
/// println!("{lit}"); |
| 86 |
/// // Prints: |
| 87 |
/// // let pretty_bencode = b"\ |
| 88 |
/// // l\ |
| 89 |
/// // i0e\ |
| 90 |
/// // i1e\ |
| 91 |
/// // e\ |
| 92 |
/// // " |
| 93 |
/// ``` |
| 94 |
#[must_use] |
| 95 |
pub fn as_rust_string_literalrust-analyzer cargo bendy 0.6.1 inspect/display/impl#[`Inspectable<'a>`]as_rust_string_literal().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 96 |
self.internal_pretty_printrust-analyzer cargo bendy 0.6.1 inspect/display/impl#[`Inspectable<'a>`]internal_pretty_print().(true) |
| 97 |
} |
| 98 |
|
| 99 |
/// Provides a [`String`] of pretty-printed bencode. |
| 100 |
/// |
| 101 |
/// # Example |
| 102 |
/// |
| 103 |
/// ``` |
| 104 |
/// # use bendy::inspect::*; |
| 105 |
/// let i = inspect(b"li0ei1ee"); |
| 106 |
/// let lit = i.as_pretty_printed(); |
| 107 |
/// println!("{lit}"); |
| 108 |
/// // Prints: |
| 109 |
/// // l |
| 110 |
/// // i0e |
| 111 |
/// // i1e |
| 112 |
/// // e |
| 113 |
/// ``` |
| 114 |
#[must_use] |
| 115 |
pub fn as_pretty_printedrust-analyzer cargo bendy 0.6.1 inspect/display/impl#[`Inspectable<'a>`]as_pretty_printed().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 116 |
self.internal_pretty_printrust-analyzer cargo bendy 0.6.1 inspect/display/impl#[`Inspectable<'a>`]internal_pretty_print().(false) |
| 117 |
} |
| 118 |
|
| 119 |
fn internal_pretty_printrust-analyzer cargo bendy 0.6.1 inspect/display/impl#[`Inspectable<'a>`]internal_pretty_print().(&self, as_literal: bool) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 120 |
fn dispatchrust-analyzer cargo bendy 0.6.1 inspect/display/dispatch().( |
| 121 |
inspectable: &Inspectablerust-analyzer cargo bendy 0.6.1 inspect/Inspectable#, |
| 122 |
indent: &mut usize, |
| 123 |
as_literal: bool, |
| 124 |
out: &mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 125 |
) { |
| 126 |
let newline = |indent: &usize, out: &mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#| { |
| 127 |
if as_literal { |
| 128 |
out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('\\'); |
| 129 |
} |
| 130 |
out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('\n'); |
| 131 |
for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().indent { |
| 132 |
out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('\t'); |
| 133 |
} |
| 134 |
}; |
| 135 |
|
| 136 |
match inspectable { |
| 137 |
x @ Inspectablerust-analyzer cargo bendy 0.6.1 inspect/Inspectable#::Rawrust-analyzer cargo bendy 0.6.1 inspect/Inspectable#Raw#(_) | x @ Inspectablerust-analyzer cargo bendy 0.6.1 inspect/Inspectable#::Stringrust-analyzer cargo bendy 0.6.1 inspect/Inspectable#String#(_) | x @ Inspectablerust-analyzer cargo bendy 0.6.1 inspect/Inspectable#::Intrust-analyzer cargo bendy 0.6.1 inspect/Inspectable#Int#(_) => { |
| 138 |
out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(x.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()); |
| 139 |
}, |
| 140 |
Inspectablerust-analyzer cargo bendy 0.6.1 inspect/Inspectable#::Listrust-analyzer cargo bendy 0.6.1 inspect/Inspectable#List#(InListrust-analyzer cargo bendy 0.6.1 inspect/InList# { itemsrust-analyzer cargo bendy 0.6.1 inspect/InList#items. }) => { |
| 141 |
out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('l'); |
| 142 |
*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().indent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 143 |
for i in items.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 144 |
newline(indent, out); |
| 145 |
dispatchrust-analyzer cargo bendy 0.6.1 inspect/display/dispatch().(i, indent, as_literal, out); |
| 146 |
} |
| 147 |
*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().indent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1; |
| 148 |
newline(indent, out); |
| 149 |
out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('e'); |
| 150 |
}, |
| 151 |
Inspectablerust-analyzer cargo bendy 0.6.1 inspect/Inspectable#::Dictrust-analyzer cargo bendy 0.6.1 inspect/Inspectable#Dict#(InDictrust-analyzer cargo bendy 0.6.1 inspect/InDict# { itemsrust-analyzer cargo bendy 0.6.1 inspect/InDict#items. }) => { |
| 152 |
out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('d'); |
| 153 |
*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().indent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 154 |
for i in items.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 155 |
let InDictEntryrust-analyzer cargo bendy 0.6.1 inspect/InDictEntry# { keyrust-analyzer cargo bendy 0.6.1 inspect/InDictEntry#key., valuerust-analyzer cargo bendy 0.6.1 inspect/InDictEntry#value. } = i; |
| 156 |
newline(indent, out); |
| 157 |
out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(key.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()); |
| 158 |
newline(indent, out); |
| 159 |
dispatchrust-analyzer cargo bendy 0.6.1 inspect/display/dispatch().(value, indent, as_literal, out); |
| 160 |
} |
| 161 |
*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().indent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1; |
| 162 |
newline(indent, out); |
| 163 |
out.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('e'); |
| 164 |
}, |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
let mut output = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 169 |
let mut indent = 0; |
| 170 |
|
| 171 |
if as_literal { |
| 172 |
output.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().("let pretty_bencode = b\"\\\n"); |
| 173 |
} |
| 174 |
dispatchrust-analyzer cargo bendy 0.6.1 inspect/display/dispatch().(self, &mut indent, as_literal, &mut output); |
| 175 |
if as_literal { |
| 176 |
output.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().("\\\n\""); |
| 177 |
} |
| 178 |
output |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
#[allow(clippy::manual_range_contains)] |
| 183 |
fn is_printable_byterust-analyzer cargo bendy 0.6.1 inspect/display/is_printable_byte().(b: u8) -> bool { |
| 184 |
40 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]le().b && b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt().127 |
| 185 |
} |
| 186 |
|
| 187 |
#[cfg(test)] |
| 188 |
mod testsrust-analyzer cargo bendy 0.6.1 inspect/display/tests/ { |
| 189 |
use superrust-analyzer cargo bendy 0.6.1 inspect/display/::*; |
| 190 |
|
| 191 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 192 |
fn valid_printing_worksrust-analyzer cargo bendy 0.6.1 inspect/display/tests/valid_printing_works().() { |
| 193 |
fn ensure_prints_asrust-analyzer cargo bendy 0.6.1 inspect/display/tests/ensure_prints_as().(b: impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]>, expected: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>) { |
| 194 |
let b = b.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(); |
| 195 |
let i = inspectrust-analyzer cargo bendy 0.6.1 inspect/inspect().(b).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 196 |
if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(e) = expected { |
| 197 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().(), e); |
| 198 |
} else { |
| 199 |
let e = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8().(b.to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 200 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i, e); |
| 201 |
} |
| 202 |
} |
| 203 |
fn ensure_roundtriprust-analyzer cargo bendy 0.6.1 inspect/display/tests/ensure_roundtrip().(b: impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]>) { |
| 204 |
ensure_prints_asrust-analyzer cargo bendy 0.6.1 inspect/display/tests/ensure_prints_as().(b, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 205 |
} |
| 206 |
ensure_roundtriprust-analyzer cargo bendy 0.6.1 inspect/display/tests/ensure_roundtrip().(b"i200e"); |
| 207 |
ensure_roundtriprust-analyzer cargo bendy 0.6.1 inspect/display/tests/ensure_roundtrip().(b"4:helo"); |
| 208 |
ensure_roundtriprust-analyzer cargo bendy 0.6.1 inspect/display/tests/ensure_roundtrip().(b"de"); |
| 209 |
ensure_roundtriprust-analyzer cargo bendy 0.6.1 inspect/display/tests/ensure_roundtrip().(b"le"); |
| 210 |
ensure_roundtriprust-analyzer cargo bendy 0.6.1 inspect/display/tests/ensure_roundtrip().(b"li2e6:inliste"); |
| 211 |
ensure_roundtriprust-analyzer cargo bendy 0.6.1 inspect/display/tests/ensure_roundtrip().(b"d1:ai1e1:bi2ee"); |
| 212 |
ensure_prints_asrust-analyzer cargo bendy 0.6.1 inspect/display/tests/ensure_prints_as().( |
| 213 |
b"d5:countli1ei2ei3ee4:null1:\x00e", |
| 214 |
Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("d5:countli1ei2ei3ee4:null1:\\x00e"), |
| 215 |
); |
| 216 |
} |
| 217 |
|
| 218 |
#[ignore] |
| 219 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| •220 |
#[cfg(feature = "std")] |
| 221 |
fn as_rust_string_literal_testrust-analyzer cargo bendy 0.6.1 inspect/display/tests/as_rust_string_literal_test().() { |
| 222 |
fn printrust-analyzer cargo bendy 0.6.1 inspect/display/tests/print().(b: impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]>) { |
| 223 |
let b = b.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(); |
| 224 |
let i = inspectrust-analyzer cargo bendy 0.6.1 inspect/inspect().(b).as_rust_string_literalrust-analyzer cargo bendy 0.6.1 inspect/display/impl#[`Inspectable<'a>`]as_rust_string_literal().(); |
| 225 |
printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("-------\n{}", i); |
| 226 |
} |
| 227 |
printrust-analyzer cargo bendy 0.6.1 inspect/display/tests/print().(b"i200e"); |
| 228 |
printrust-analyzer cargo bendy 0.6.1 inspect/display/tests/print().(b"4:helo"); |
| 229 |
printrust-analyzer cargo bendy 0.6.1 inspect/display/tests/print().(b"de"); |
| 230 |
printrust-analyzer cargo bendy 0.6.1 inspect/display/tests/print().(b"le"); |
| 231 |
printrust-analyzer cargo bendy 0.6.1 inspect/display/tests/print().(b"li2e6:inliste"); |
| 232 |
printrust-analyzer cargo bendy 0.6.1 inspect/display/tests/print().(b"d1:ai1e1:bi2ee"); |
| 233 |
printrust-analyzer cargo bendy 0.6.1 inspect/display/tests/print().(b"d5:countli1ei2ei3ee4:null1:\x00e"); |
| 234 |
let ap = all_printables_bencode_listrust-analyzer cargo bendy 0.6.1 inspect/display/tests/all_printables_bencode_list().(); |
| 235 |
printrust-analyzer cargo bendy 0.6.1 inspect/display/tests/print().(&ap); |
| 236 |
|
| 237 |
panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!() |
| 238 |
} |
| 239 |
|
| 240 |
#[ignore] |
| 241 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| •242 |
#[cfg(feature = "std")] |
| 243 |
fn debug_print_testrust-analyzer cargo bendy 0.6.1 inspect/display/tests/debug_print_test().() { |
| 244 |
let i = inspectrust-analyzer cargo bendy 0.6.1 inspect/inspect().(b"i200e"); |
| 245 |
dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(i); |
| 246 |
let i = inspectrust-analyzer cargo bendy 0.6.1 inspect/inspect().(b"4:helo"); |
| 247 |
dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(i); |
| 248 |
let i = inspectrust-analyzer cargo bendy 0.6.1 inspect/inspect().(b"de"); |
| 249 |
dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(i); |
| 250 |
let i = inspectrust-analyzer cargo bendy 0.6.1 inspect/inspect().(b"le"); |
| 251 |
dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(i); |
| 252 |
let i = inspectrust-analyzer cargo bendy 0.6.1 inspect/inspect().(b"li2e4:liste"); |
| 253 |
dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(i); |
| 254 |
let i = inspectrust-analyzer cargo bendy 0.6.1 inspect/inspect().(b"d1:ai1e1:bi2ee"); |
| 255 |
dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(i); |
| 256 |
panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!() |
| 257 |
} |
| 258 |
|
| 259 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 260 |
fn as_rust_string_literal_doesnt_break_quotingrust-analyzer cargo bendy 0.6.1 inspect/display/tests/as_rust_string_literal_doesnt_break_quoting().() { |
| 261 |
// We must not considuer double quote symbols printable, since |
| 262 |
// we don't escape them or turn them into \x22 in as_rust_string_literal |
| 263 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_printable_byterust-analyzer cargo bendy 0.6.1 inspect/display/is_printable_byte().(b'"')); |
| 264 |
} |
| 265 |
|
| 266 |
fn all_printables_bencode_listrust-analyzer cargo bendy 0.6.1 inspect/display/tests/all_printables_bencode_list().() -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> { |
| 267 |
let mut ap = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 268 |
ap.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(b'l'); |
| 269 |
for b in 40_u8..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#127 { |
| 270 |
// Just checking that the printable byte ranges are synced |
| 271 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(is_printable_byterust-analyzer cargo bendy 0.6.1 inspect/display/is_printable_byte().(b)); |
| 272 |
ap.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(b'1'); |
| 273 |
ap.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(b':'); |
| 274 |
ap.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(b); |
| 275 |
} |
| 276 |
ap.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(b'e'); |
| 277 |
ap |
| 278 |
} |
| 279 |
} |