Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 //! The purpose of this crate is to extend the `UpperHex` and `LowerHex`
2 //! traits to slices, as well as the integers it is currently implemented for.
3 //!
4 //! # Examples
5 //!
6 //! ```rust
7 //! extern crate hex_slice;
8 //! use hex_slice::AsHex;
9 //!
10 //! fn main() {
11 //! let foo = vec![0u32, 1 ,2 ,3];
12 //! println!("{:x}", foo.as_hex());
13 //! }
14 //! ```
15
16 #![no_std]
17
18 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/;
19 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/::Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#;
20
21 pub struct Hexrust-analyzer cargo hex-slice 0.1.4 Hex#<'a, T: 'a>(&'a [T]);
22
23 pub struct PlainHexrust-analyzer cargo hex-slice 0.1.4 PlainHex#<'a, T: 'a> {
24 slicerust-analyzer cargo hex-slice 0.1.4 PlainHex#slice.: &'a [T],
25 with_spacesrust-analyzer cargo hex-slice 0.1.4 PlainHex#with_spaces.: bool,
26 }
27
28 pub trait AsHexrust-analyzer cargo hex-slice 0.1.4 AsHex# {
29 type Itemrust-analyzer cargo hex-slice 0.1.4 AsHex#Item#;
30 fn as_hexrust-analyzer cargo hex-slice 0.1.4 AsHex#as_hex().<'a>(&'a self) -> Hexrust-analyzer cargo hex-slice 0.1.4 Hex#<'a, Self::Itemrust-analyzer cargo hex-slice 0.1.4 AsHex#Item#>;
31
32 fn plain_hexrust-analyzer cargo hex-slice 0.1.4 AsHex#plain_hex().<'a>(&'a self, with_spaces: bool) -> PlainHexrust-analyzer cargo hex-slice 0.1.4 PlainHex#<'a, Self::Itemrust-analyzer cargo hex-slice 0.1.4 AsHex#Item#>;
33 }
34
35 fn fmt_inner_hexrust-analyzer cargo hex-slice 0.1.4 fmt_inner_hex().<T, F: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&T, &mut 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#) -> 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#>(slice: &[T], f: &mut 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#, fmt_fn: F, with_spaces: bool) -> 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# {
36 for (i, val) in slice.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
37 if with_spaces && i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 {
38 f.write_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'_>`][Write]write_char().(' ')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
39 }
40 fmt_fn(val, f)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
41 }
42 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
43 }
44
45 impl<'a, T> Hexrust-analyzer cargo hex-slice 0.1.4 Hex#<'a, T> {
46 pub fn hexrust-analyzer cargo hex-slice 0.1.4 impl#[`Hex<'a, T>`]hex().(slice: &'a [T]) -> Hexrust-analyzer cargo hex-slice 0.1.4 Hex#<'a, T> {
47 Hexrust-analyzer cargo hex-slice 0.1.4 Hex#(slice)
48 }
49 }
50
51 impl<'a, T: fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::LowerHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/LowerHex#> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::LowerHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/LowerHex# for Hexrust-analyzer cargo hex-slice 0.1.4 Hex#<'a, T> {
52 fn fmtrust-analyzer cargo hex-slice 0.1.4 impl#[`Hex<'a, T>`][LowerHex]fmt().(&self, f: &mut 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#) -> 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# {
53 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "[")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
54 fmt_inner_hexrust-analyzer cargo hex-slice 0.1.4 fmt_inner_hex().(self.0rust-analyzer cargo hex-slice 0.1.4 Hex#0., f, fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::LowerHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/LowerHex#::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/LowerHex#fmt()., true)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
55 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "]")
56 }
57 }
58
59 impl<'a, T: fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::UpperHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/UpperHex#> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::UpperHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/UpperHex# for Hexrust-analyzer cargo hex-slice 0.1.4 Hex#<'a, T> {
60 fn fmtrust-analyzer cargo hex-slice 0.1.4 impl#[`Hex<'a, T>`][UpperHex]fmt().(&self, f: &mut 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#) -> 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# {
61 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "[")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
62 fmt_inner_hexrust-analyzer cargo hex-slice 0.1.4 fmt_inner_hex().(self.0rust-analyzer cargo hex-slice 0.1.4 Hex#0., f, fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::UpperHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/UpperHex#::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/UpperHex#fmt()., true)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
63 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "]")
64 }
65 }
66
67 impl<'a, T: fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::LowerHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/LowerHex#> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::LowerHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/LowerHex# for PlainHexrust-analyzer cargo hex-slice 0.1.4 PlainHex#<'a, T> {
68 fn fmtrust-analyzer cargo hex-slice 0.1.4 impl#[`PlainHex<'a, T>`][LowerHex]fmt().(&self, f: &mut 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#) -> 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# {
69 fmt_inner_hexrust-analyzer cargo hex-slice 0.1.4 fmt_inner_hex().(self.slicerust-analyzer cargo hex-slice 0.1.4 PlainHex#slice., f, fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::LowerHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/LowerHex#::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/LowerHex#fmt()., self.with_spacesrust-analyzer cargo hex-slice 0.1.4 PlainHex#with_spaces.)
70 }
71 }
72
73 impl<'a, T: fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::UpperHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/UpperHex#> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::UpperHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/UpperHex# for PlainHexrust-analyzer cargo hex-slice 0.1.4 PlainHex#<'a, T> {
74 fn fmtrust-analyzer cargo hex-slice 0.1.4 impl#[`PlainHex<'a, T>`][UpperHex]fmt().(&self, f: &mut 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#) -> 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# {
75 fmt_inner_hexrust-analyzer cargo hex-slice 0.1.4 fmt_inner_hex().(self.slicerust-analyzer cargo hex-slice 0.1.4 PlainHex#slice., f, fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::UpperHexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/UpperHex#::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/UpperHex#fmt()., self.with_spacesrust-analyzer cargo hex-slice 0.1.4 PlainHex#with_spaces.)
76 }
77 }
78
79 impl<T> AsHexrust-analyzer cargo hex-slice 0.1.4 AsHex# for [T] {
80 type Itemrust-analyzer cargo hex-slice 0.1.4 impl#[`[T]`][AsHex]Item# = T;
81 fn as_hexrust-analyzer cargo hex-slice 0.1.4 impl#[`[T]`][AsHex]as_hex().<'a>(&'a self) -> Hexrust-analyzer cargo hex-slice 0.1.4 Hex#<'a, Selfrust-analyzer cargo hex-slice 0.1.4 impl#[`[T]`][AsHex]::Itemrust-analyzer cargo hex-slice 0.1.4 AsHex#Item#> {
82 Hexrust-analyzer cargo hex-slice 0.1.4 Hex#::hexrust-analyzer cargo hex-slice 0.1.4 impl#[`Hex<'a, T>`]hex().(self)
83 }
84
85 fn plain_hexrust-analyzer cargo hex-slice 0.1.4 impl#[`[T]`][AsHex]plain_hex().<'a>(&'a self, with_spaces: bool) -> PlainHexrust-analyzer cargo hex-slice 0.1.4 PlainHex#<'a, Selfrust-analyzer cargo hex-slice 0.1.4 impl#[`[T]`][AsHex]::Itemrust-analyzer cargo hex-slice 0.1.4 AsHex#Item#> {
86 PlainHexrust-analyzer cargo hex-slice 0.1.4 PlainHex# {
87 slicerust-analyzer cargo hex-slice 0.1.4 PlainHex#slice.: self,
88 with_spacesrust-analyzer cargo hex-slice 0.1.4 PlainHex#with_spaces.,
89 }
90 }
91 }