| 1 | use proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::Spanrust-analyzer cargo proc-macro2 1.0.107 Span#; |
| 2 | |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 4 | fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::{selfrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#}, |
| 5 | opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#, |
| 6 | }; |
| 7 | |
| 8 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 9 | pub(craterust-analyzer cargo const_format_proc_macros 0.2.34 crate/) struct ParseErrorrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseError# { |
| 10 | pub(craterust-analyzer cargo const_format_proc_macros 0.2.34 crate/) posrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseError#pos.: usize, |
| 11 | pub(craterust-analyzer cargo const_format_proc_macros 0.2.34 crate/) kindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseError#kind.: ParseErrorKindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#, |
| 12 | } |
| 13 | |
| 14 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 15 | pub(craterust-analyzer cargo const_format_proc_macros 0.2.34 crate/) enum ParseErrorKindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind# { |
| 16 | /// A `{` that wasn't closed. |
| 17 | UnclosedArgrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#UnclosedArg#, |
| 18 | /// A `}` that doesn't close an argument. |
| 19 | InvalidClosedArgrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#InvalidClosedArg#, |
| 20 | /// When parsing the number of a positional arguments |
| 21 | NotANumberrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#NotANumber# { |
| 22 | whatrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#NotANumber#what.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 23 | }, |
| 24 | /// When parsing the identifier of a named argument |
| 25 | NotAnIdentrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#NotAnIdent# { |
| 26 | whatrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#NotAnIdent#what.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 27 | }, |
| 28 | UnknownFormattingrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#UnknownFormatting# { |
| 29 | whatrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#UnknownFormatting#what.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 30 | }, |
| 31 | } |
| 32 | |
| 33 | #[allow(dead_code)] |
| 34 | impl ParseErrorKindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind# { |
| 35 | pub fn not_a_numberrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/impl#[ParseErrorKind]not_a_number().(what: &str) -> Selfrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/impl#[ParseErrorKind] { |
| 36 | Selfrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/impl#[ParseErrorKind]::NotANumberrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#NotANumber# { |
| 37 | whatrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#NotANumber#what.: what.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 38 | } |
| 39 | } |
| 40 | pub fn not_an_identrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/impl#[ParseErrorKind]not_an_ident().(what: &str) -> Selfrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/impl#[ParseErrorKind] { |
| 41 | Selfrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/impl#[ParseErrorKind]::NotAnIdentrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#NotAnIdent# { |
| 42 | whatrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#NotAnIdent#what.: what.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 43 | } |
| 44 | } |
| 45 | pub fn unknown_formattingrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/impl#[ParseErrorKind]unknown_formatting().(what: &str) -> Selfrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/impl#[ParseErrorKind] { |
| 46 | Selfrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/impl#[ParseErrorKind]::UnknownFormattingrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#UnknownFormatting# { |
| 47 | whatrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#UnknownFormatting#what.: what.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | //////////////////////////////////////////////////////////////////////////////// |
| 53 | |
| 54 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 55 | pub(craterust-analyzer cargo const_format_proc_macros 0.2.34 crate/) struct DisplayParseErrorrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/DisplayParseError#<'a> { |
| 56 | pub(craterust-analyzer cargo const_format_proc_macros 0.2.34 crate/) strrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/DisplayParseError#str.: &'a str, |
| 57 | pub(craterust-analyzer cargo const_format_proc_macros 0.2.34 crate/) error_spanrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/DisplayParseError#error_span.: Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize>, |
| 58 | pub(craterust-analyzer cargo const_format_proc_macros 0.2.34 crate/) kindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/DisplayParseError#kind.: ParseErrorKindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#, |
| 59 | } |
| 60 | impl ParseErrorrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseError# { |
| 61 | fn error_spanrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/impl#[ParseError]error_span().(&self) -> Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize> { |
| 62 | let len = match &self.kindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseError#kind. { |
| 63 | ParseErrorKindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#::UnclosedArgrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#UnclosedArg# => 0, |
| 64 | ParseErrorKindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#::InvalidClosedArgrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#InvalidClosedArg# => 0, |
| 65 | ParseErrorKindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#::NotANumberrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#NotANumber# { whatrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#NotANumber#what. } => what.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().(), |
| 66 | ParseErrorKindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#::NotAnIdentrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#NotAnIdent# { whatrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#NotAnIdent#what. } => what.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().(), |
| 67 | ParseErrorKindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#::UnknownFormattingrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#UnknownFormatting# { whatrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#UnknownFormatting#what. } => what.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().(), |
| 68 | }; |
| 69 | |
| 70 | self.posrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseError#pos...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#self.posrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseError#pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().len |
| 71 | } |
| 72 | |
| 73 | pub(craterust-analyzer cargo const_format_proc_macros 0.2.34 crate/) fn into_crate_errrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/impl#[ParseError]into_crate_err().(self, span: Spanrust-analyzer cargo proc-macro2 1.0.107 Span#, original_str: &str) -> craterust-analyzer cargo const_format_proc_macros 0.2.34 crate/::Errorrust-analyzer cargo const_format_proc_macros 0.2.34 error/Error# { |
| 74 | let display = DisplayParseErrorrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/DisplayParseError# { |
| 75 | strrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/DisplayParseError#str.: original_str, |
| 76 | error_spanrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/DisplayParseError#error_span.: self.error_spanrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/impl#[ParseError]error_span().(), |
| 77 | kindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/DisplayParseError#kind.: self.kindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseError#kind., |
| 78 | }; |
| 79 | |
| 80 | craterust-analyzer cargo const_format_proc_macros 0.2.34 crate/::Errorrust-analyzer cargo const_format_proc_macros 0.2.34 error/Error#::newrust-analyzer cargo const_format_proc_macros 0.2.34 error/impl#[Error]new().(span, display) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | impl Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for ParseErrorKindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind# { |
| 85 | fn fmtrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/impl#[ParseErrorKind][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 86 | match self { |
| 87 | ParseErrorKindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#::UnclosedArgrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#UnclosedArg# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("unclosed argument"), |
| 88 | ParseErrorKindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#::InvalidClosedArgrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#InvalidClosedArg# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("`}` closing a nonexistent argument"), |
| 89 | ParseErrorKindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#::NotANumberrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#NotANumber# { whatrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#NotANumber#what. } => writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(f, "not a number: \"{}\"", what), |
| 90 | ParseErrorKindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#::NotAnIdentrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#NotAnIdent# { whatrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#NotAnIdent#what. } => { |
| 91 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(f, "not a valid identifier: \"{}\"", what) |
| 92 | } |
| 93 | ParseErrorKindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#::UnknownFormattingrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#UnknownFormatting# { whatrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/ParseErrorKind#UnknownFormatting#what. } => { |
| 94 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(f, "unknown formatting: \"{}\"", what) |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | impl Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for DisplayParseErrorrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/DisplayParseError#<'_> { |
| 101 | fn fmtrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/impl#[`DisplayParseError<'_>`][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 102 | f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("failed to parse the format string ")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 103 | |
| 104 | // Gets the amount of chars up to the error, |
| 105 | // this is good enough for most cases, |
| 106 | // but doesn't acount for multi-char characters. |
| 107 | let chars = self.strrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/DisplayParseError#str.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#self.error_spanrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/DisplayParseError#error_span..startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start.]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]count().(); |
| 108 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(f, "at the character number {}, ", chars)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 109 | |
| 110 | Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#::fmtrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/impl#[ParseErrorKind][Display]fmt().(&self.kindrust-analyzer cargo const_format_proc_macros 0.2.34 format_str/errors/DisplayParseError#kind., f)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 111 | |
| 112 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 113 | } |
| 114 | } |