| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/; |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#; |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/; |
| 5 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/::Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#; |
| 6 | |
| 7 | use types::*; |
| 8 | |
| 9 | #[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:)] |
| 10 | pub struct Formatterrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#<'a, 'b> { |
| 11 | pub keyrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#key.: &'a str, |
| 12 | fillrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#fill.: char, |
| 13 | alignrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#align.: Alignmentrust-analyzer cargo strfmt 0.2.4 types/Alignment#, // default Right for numbers, Left for strings |
| 14 | signrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#sign.: Signrust-analyzer cargo strfmt 0.2.4 types/Sign#, |
| 15 | alternaterust-analyzer cargo strfmt 0.2.4 formatter/Formatter#alternate.: bool, |
| 16 | widthrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#width.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>, |
| 17 | thousandsrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#thousands.: bool, |
| 18 | precisionrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#precision.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>, |
| 19 | tyrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#ty.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<char>, |
| 20 | buffrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#buff.: &'b mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 21 | patternrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#pattern.: &'a str, |
| 22 | } |
| 23 | |
| 24 | fn is_alignment_tokenrust-analyzer cargo strfmt 0.2.4 formatter/is_alignment_token().(c: char) -> bool { |
| 25 | match c { |
| 26 | '=' | '<' | '^' | '>' => true, |
| 27 | _ => false, |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | fn is_sign_elementrust-analyzer cargo strfmt 0.2.4 formatter/is_sign_element().(c: char) -> bool { |
| 32 | match c { |
| 33 | ' ' | '-' | '+' => true, |
| 34 | _ => false, |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | fn is_type_elementrust-analyzer cargo strfmt 0.2.4 formatter/is_type_element().(c: char) -> bool { |
| 39 | match c { |
| 40 | 'b' | 'o' | 'x' | 'X' | 'e' | 'E' | 'f' | 'F' | '%' | 's' | '?' => true, |
| 41 | _ => false, |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | // get an integer from pos, returning the number of bytes |
| 46 | // consumed and the integer |
| 47 | fn get_integerrust-analyzer cargo strfmt 0.2.4 formatter/get_integer().(s: &[u8], pos: usize) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<i64>) { |
| 48 | let (_, rest) = s.split_atrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_at().(pos); |
| 49 | let mut consumed: usize = 0; |
| 50 | for b in rest { |
| 51 | match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().b as char { |
| 52 | '0'..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#'9' => {} |
| 53 | _ => break, |
| 54 | }; |
| 55 | consumed 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; |
| 56 | } |
| 57 | if consumed rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 58 | (0, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) |
| 59 | } else { |
| 60 | let (intstr, _) = rest.split_atrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_at().(consumed); |
| 61 | let val = unsafe { |
| 62 | // I think I can be reasonably sure that 0-9 chars are utf8 :) |
| 63 | match strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8_unchecked().(intstr).parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<i64>() { |
| 64 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(v) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v), |
| 65 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 66 | } |
| 67 | }; |
| 68 | (consumed, val) |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | #[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:)] |
| 73 | /// The format struct as it is defined in the python source |
| 74 | struct FmtPyrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy# { |
| 75 | pub fillrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#fill.: char, |
| 76 | pub alignrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#align.: char, |
| 77 | pub alternaterust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#alternate.: bool, |
| 78 | pub signrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#sign.: char, |
| 79 | pub widthrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#width.: i64, |
| 80 | pub thousandsrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#thousands.: bool, |
| 81 | pub precisionrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#precision.: i64, |
| 82 | pub tyrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#ty.: char, |
| 83 | } |
| 84 | |
| 85 | fn parse_like_pythonrust-analyzer cargo strfmt 0.2.4 formatter/parse_like_python().(rest: &str) -> Resultrust-analyzer cargo strfmt 0.2.4 types/Result#<FmtPyrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#> { |
| 86 | // The rest of this was pretty much strait up copied from python's format parser |
| 87 | // All credit goes to python source file: formatter_unicode.c |
| 88 | // |
| 89 | |
| 90 | let mut format = FmtPyrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy# { |
| 91 | fillrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#fill.: ' ', |
| 92 | alignrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#align.: '\0', |
| 93 | alternaterust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#alternate.: false, |
| 94 | signrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#sign.: '\0', |
| 95 | widthrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#width.: -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().1, |
| 96 | thousandsrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#thousands.: false, |
| 97 | precisionrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#precision.: -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().1, |
| 98 | tyrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#ty.: '\0', |
| 99 | }; |
| 100 | let mut chars = rest.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().(); |
| 101 | let fake_fill = match chars.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]next().() { |
| 102 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c) => c, |
| 103 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(format), |
| 104 | }; |
| 105 | // from now on all format characters MUST be valid |
| 106 | // ASCII characters (fill and identifier were the |
| 107 | // only ones that weren't. |
| 108 | // Therefore we can use bytes for the rest |
| 109 | let rest = rest.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(); |
| 110 | let mut align_specified = false; |
| 111 | let mut fill_specified = false; |
| 112 | |
| 113 | let end: usize = rest.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(); |
| 114 | let mut pos: usize = 0; |
| 115 | |
| 116 | // If the second char is an alignment token, |
| 117 | // then fake_fill as fill |
| 118 | if end rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().1 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().fake_fill.len_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]len_utf8().() |
| 119 | && is_alignment_tokenrust-analyzer cargo strfmt 0.2.4 formatter/is_alignment_token().(rest[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().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().fake_fill.len_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]len_utf8().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as char) |
| 120 | { |
| 121 | format.alignrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#align. = rest[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().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().fake_fill.len_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]len_utf8().()]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as char; |
| 122 | format.fillrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#fill. = fake_fill; |
| 123 | fill_specified = true; |
| 124 | align_specified = true; |
| 125 | pos 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 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().fake_fill.len_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]len_utf8().(); |
| 126 | } else if end rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().1 && is_alignment_tokenrust-analyzer cargo strfmt 0.2.4 formatter/is_alignment_token().(fake_fill) { |
| 127 | format.alignrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#align. = fake_fill; |
| 128 | pos 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().fake_fill.len_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]len_utf8().(); |
| 129 | } |
| 130 | |
| 131 | // Parse the various sign options |
| 132 | if end rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().1 && is_sign_elementrust-analyzer cargo strfmt 0.2.4 formatter/is_sign_element().(rest[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pos]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as char) { |
| 133 | format.signrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#sign. = rest[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pos]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as char; |
| 134 | pos 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; |
| 135 | } |
| 136 | |
| 137 | // If the next character is #, we're in alternate mode. This only |
| 138 | // applies to integers. |
| 139 | if end rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().1 && rest[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pos]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as char rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'#' { |
| 140 | format.alternaterust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#alternate. = true; |
| 141 | pos 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; |
| 142 | } |
| 143 | |
| 144 | // The special case for 0-padding (backwards compat) |
| 145 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().fill_specified && end rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().1 && rest[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pos]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 cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().'0' as u8 { |
| 146 | format.fillrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#fill. = '0'; |
| 147 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().align_specified { |
| 148 | format.alignrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#align. = '='; |
| 149 | } |
| 150 | pos 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; |
| 151 | } |
| 152 | |
| 153 | // check to make sure that val is good |
| 154 | let (consumed, val) = get_integerrust-analyzer cargo strfmt 0.2.4 formatter/get_integer().(rest, pos); |
| 155 | pos 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().consumed; |
| 156 | if consumed rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0 { |
| 157 | match val { |
| 158 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 159 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FmtErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#::Invalidrust-analyzer cargo strfmt 0.2.4 types/FmtError#Invalid#( |
| 160 | "overflow error when parsing width".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 161 | )) |
| 162 | } |
| 163 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) => { |
| 164 | format.widthrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#width. = v; |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | // Comma signifies add thousands separators |
| 170 | if end rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().pos 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 && rest[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pos]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as char rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().',' { |
| 171 | format.thousandsrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#thousands. = true; |
| 172 | pos 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; |
| 173 | } |
| 174 | |
| 175 | // Parse field precision |
| 176 | if end rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().pos 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 && rest[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pos]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as char rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'.' { |
| 177 | pos 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; |
| 178 | |
| 179 | let (consumed, val) = get_integerrust-analyzer cargo strfmt 0.2.4 formatter/get_integer().(rest, pos); |
| 180 | if consumed rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0 { |
| 181 | match val { |
| 182 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 183 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FmtErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#::Invalidrust-analyzer cargo strfmt 0.2.4 types/FmtError#Invalid#( |
| 184 | "overflow error when parsing precision".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 185 | )) |
| 186 | } |
| 187 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) => { |
| 188 | format.precisionrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#precision. = v; |
| 189 | } |
| 190 | } |
| 191 | } else { |
| 192 | // Not having a precision after a dot is an error. |
| 193 | if consumed rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 194 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FmtErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#::Invalidrust-analyzer cargo strfmt 0.2.4 types/FmtError#Invalid#( |
| 195 | "Format specifier missing precision".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 196 | )); |
| 197 | } |
| 198 | } |
| 199 | pos 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().consumed; |
| 200 | } |
| 201 | |
| 202 | // Finally, parse the type field. |
| 203 | if end rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().pos 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().1 { |
| 204 | // More than one char remain, invalid format specifier. |
| 205 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FmtErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#::Invalidrust-analyzer cargo strfmt 0.2.4 types/FmtError#Invalid#("Invalid format specifier".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 206 | } |
| 207 | |
| 208 | if end rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 { |
| 209 | format.tyrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#ty. = rest[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pos]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as char; |
| 210 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_type_elementrust-analyzer cargo strfmt 0.2.4 formatter/is_type_element().(format.tyrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#ty.) { |
| 211 | let mut msg = 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().(); |
| 212 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(msg, "Invalid type specifier: {:?}", format.tyrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#ty.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 213 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FmtErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#::TypeErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#TypeError#(msg)); |
| 214 | } |
| 215 | // pos+=1; |
| 216 | } |
| 217 | |
| 218 | // Do as much validating as we can, just by looking at the format |
| 219 | // specifier. Do not take into account what type of formatting |
| 220 | // we're doing (int, float, string). |
| 221 | if format.thousandsrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#thousands. { |
| 222 | match format.tyrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#ty. { |
| 223 | 'd' | 'e' | 'f' | 'g' | 'E' | 'G' | '%' | 'F' | '\0' => {} /* These are allowed. See PEP 378.*/ |
| 224 | |
| 225 | _ => { |
| 226 | let mut msg = 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().(); |
| 227 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(msg, "Invalid comma type: {}", format.tyrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#ty.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 228 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FmtErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#::Invalidrust-analyzer cargo strfmt 0.2.4 types/FmtError#Invalid#(msg)); |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(format) |
| 233 | } |
| 234 | |
| 235 | impl<'a, 'b> Formatterrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#<'a, 'b> { |
| 236 | /// create Formatter from format string |
| 237 | pub fn from_strrust-analyzer cargo strfmt 0.2.4 formatter/impl#[`Formatter<'a, 'b>`]from_str().(s: &'a str, buff: &'b mut Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> Resultrust-analyzer cargo strfmt 0.2.4 types/Result#<Formatterrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#<'a, 'b>> { |
| 238 | let mut found_colon = false; |
| 239 | let mut chars = s.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().(); |
| 240 | let mut c = match chars.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]next().() { |
| 241 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(':') | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 242 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FmtErrorrust-analyzer cargo strfmt 0.2.4 types/FmtError#::Invalidrust-analyzer cargo strfmt 0.2.4 types/FmtError#Invalid#("must specify identifier".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())) |
| 243 | } |
| 244 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c) => c, |
| 245 | }; |
| 246 | let mut consumed = 0; |
| 247 | // find the identifier |
| 248 | loop { |
| 249 | consumed 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().c.len_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]len_utf8().(); |
| 250 | if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().':' { |
| 251 | found_colon = true; |
| 252 | break; |
| 253 | } |
| 254 | c = match chars.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]next().() { |
| 255 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c) => c, |
| 256 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 257 | break; |
| 258 | } |
| 259 | }; |
| 260 | } |
| 261 | let (identifier, rest) = s.split_atrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_at().(consumed); |
| 262 | let identifier = if found_colon { |
| 263 | let (i, _) = identifier.split_atrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_at().(identifier.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1); // get rid of ':' |
| 264 | i |
| 265 | } else { |
| 266 | identifier |
| 267 | }; |
| 268 | |
| 269 | let format = parse_like_pythonrust-analyzer cargo strfmt 0.2.4 formatter/parse_like_python().(rest)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 270 | |
| 271 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Formatterrust-analyzer cargo strfmt 0.2.4 formatter/Formatter# { |
| 272 | keyrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#key.: identifier, |
| 273 | fillrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#fill.: format.fillrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#fill., |
| 274 | alignrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#align.: match format.alignrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#align. { |
| 275 | '\0' => Alignmentrust-analyzer cargo strfmt 0.2.4 types/Alignment#::Unspecifiedrust-analyzer cargo strfmt 0.2.4 types/Alignment#Unspecified#, |
| 276 | '<' => Alignmentrust-analyzer cargo strfmt 0.2.4 types/Alignment#::Leftrust-analyzer cargo strfmt 0.2.4 types/Alignment#Left#, |
| 277 | '^' => Alignmentrust-analyzer cargo strfmt 0.2.4 types/Alignment#::Centerrust-analyzer cargo strfmt 0.2.4 types/Alignment#Center#, |
| 278 | '>' => Alignmentrust-analyzer cargo strfmt 0.2.4 types/Alignment#::Rightrust-analyzer cargo strfmt 0.2.4 types/Alignment#Right#, |
| 279 | '=' => Alignmentrust-analyzer cargo strfmt 0.2.4 types/Alignment#::Equalrust-analyzer cargo strfmt 0.2.4 types/Alignment#Equal#, |
| 280 | _ => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!(), |
| 281 | }, |
| 282 | signrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#sign.: match format.signrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#sign. { |
| 283 | '\0' => Signrust-analyzer cargo strfmt 0.2.4 types/Sign#::Unspecifiedrust-analyzer cargo strfmt 0.2.4 types/Sign#Unspecified#, |
| 284 | '+' => Signrust-analyzer cargo strfmt 0.2.4 types/Sign#::Plusrust-analyzer cargo strfmt 0.2.4 types/Sign#Plus#, |
| 285 | '-' => Signrust-analyzer cargo strfmt 0.2.4 types/Sign#::Minusrust-analyzer cargo strfmt 0.2.4 types/Sign#Minus#, |
| 286 | ' ' => Signrust-analyzer cargo strfmt 0.2.4 types/Sign#::Spacerust-analyzer cargo strfmt 0.2.4 types/Sign#Space#, |
| 287 | _ => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!(), |
| 288 | }, |
| 289 | alternaterust-analyzer cargo strfmt 0.2.4 formatter/Formatter#alternate.: format.alternaterust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#alternate., |
| 290 | widthrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#width.: match format.widthrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#width. { |
| 291 | -1 => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 292 | _ => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(format.widthrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#width. as usize), |
| 293 | }, |
| 294 | thousandsrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#thousands.: format.thousandsrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#thousands., |
| 295 | precisionrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#precision.: match format.precisionrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#precision. { |
| 296 | -1 => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 297 | _ => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(format.precisionrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#precision. as usize), |
| 298 | }, |
| 299 | tyrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#ty.: match format.tyrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#ty. { |
| 300 | '\0' => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 301 | _ => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(format.tyrust-analyzer cargo strfmt 0.2.4 formatter/FmtPy#ty.), |
| 302 | }, |
| 303 | buffrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#buff.: buff, |
| 304 | patternrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#pattern.: s, |
| 305 | }) |
| 306 | } |
| 307 | |
| 308 | /// call this to re-write the original format string verbatum |
| 309 | /// back to the output |
| 310 | pub fn skiprust-analyzer cargo strfmt 0.2.4 formatter/impl#[`Formatter<'a, 'b>`]skip().(mut self) -> Resultrust-analyzer cargo strfmt 0.2.4 types/Result#<()> { |
| 311 | self.buffrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#buff..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('{'); |
| 312 | self.write_strrust-analyzer cargo strfmt 0.2.4 formatter/impl#[`Formatter<'a, 'b>`][Write]write_str().(self.patternrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#pattern.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 313 | self.buffrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#buff..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('}'); |
| 314 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 315 | } |
| 316 | |
| 317 | /// fill getter |
| 318 | pub fn fillrust-analyzer cargo strfmt 0.2.4 formatter/impl#[`Formatter<'a, 'b>`]fill().(&self) -> char { |
| 319 | self.fillrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#fill. |
| 320 | } |
| 321 | |
| 322 | /// align getter |
| 323 | pub fn alignrust-analyzer cargo strfmt 0.2.4 formatter/impl#[`Formatter<'a, 'b>`]align().(&self) -> Alignmentrust-analyzer cargo strfmt 0.2.4 types/Alignment# { |
| 324 | self.alignrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#align..clonerust-analyzer cargo strfmt 0.2.4 types/impl#[Alignment][Clone]clone().() |
| 325 | } |
| 326 | |
| 327 | // provide default for unspecified alignment |
| 328 | pub fn set_default_alignrust-analyzer cargo strfmt 0.2.4 formatter/impl#[`Formatter<'a, 'b>`]set_default_align().(&mut self, align: Alignmentrust-analyzer cargo strfmt 0.2.4 types/Alignment#) { |
| 329 | if self.alignrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#align. rust-analyzer cargo strfmt 0.2.4 types/impl#[Alignment][`PartialEq<Self>`]eq().==rust-analyzer cargo strfmt 0.2.4 types/impl#[Alignment][`PartialEq<Self>`]eq(). rust-analyzer cargo strfmt 0.2.4 types/impl#[Alignment][`PartialEq<Self>`]eq().Alignmentrust-analyzer cargo strfmt 0.2.4 types/Alignment#::Unspecifiedrust-analyzer cargo strfmt 0.2.4 types/Alignment#Unspecified# { |
| 330 | self.alignrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#align. = align |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | /// width getter |
| 335 | pub fn widthrust-analyzer cargo strfmt 0.2.4 formatter/impl#[`Formatter<'a, 'b>`]width().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize> { |
| 336 | self.widthrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#width. |
| 337 | } |
| 338 | |
| 339 | /// thousands getter |
| 340 | pub fn thousandsrust-analyzer cargo strfmt 0.2.4 formatter/impl#[`Formatter<'a, 'b>`]thousands().(&self) -> bool { |
| 341 | self.thousandsrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#thousands. |
| 342 | } |
| 343 | |
| 344 | /// precision getter |
| 345 | pub fn precisionrust-analyzer cargo strfmt 0.2.4 formatter/impl#[`Formatter<'a, 'b>`]precision().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize> { |
| 346 | self.precisionrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#precision. |
| 347 | } |
| 348 | |
| 349 | /// set precision to None, used for formatting int, float, etc |
| 350 | pub fn set_precisionrust-analyzer cargo strfmt 0.2.4 formatter/impl#[`Formatter<'a, 'b>`]set_precision().(&mut self, precision: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 351 | self.precisionrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#precision. = precision; |
| 352 | } |
| 353 | |
| 354 | /// sign getter |
| 355 | pub fn signrust-analyzer cargo strfmt 0.2.4 formatter/impl#[`Formatter<'a, 'b>`]sign().(&self) -> Signrust-analyzer cargo strfmt 0.2.4 types/Sign# { |
| 356 | self.signrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#sign..clonerust-analyzer cargo strfmt 0.2.4 types/impl#[Sign][Clone]clone().() |
| 357 | } |
| 358 | |
| 359 | /// sign plus getter |
| 360 | /// here because it is in fmt::Formatter |
| 361 | pub fn sign_plusrust-analyzer cargo strfmt 0.2.4 formatter/impl#[`Formatter<'a, 'b>`]sign_plus().(&self) -> bool { |
| 362 | self.signrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#sign. rust-analyzer cargo strfmt 0.2.4 types/impl#[Sign][`PartialEq<Self>`]eq().==rust-analyzer cargo strfmt 0.2.4 types/impl#[Sign][`PartialEq<Self>`]eq(). rust-analyzer cargo strfmt 0.2.4 types/impl#[Sign][`PartialEq<Self>`]eq().Signrust-analyzer cargo strfmt 0.2.4 types/Sign#::Plusrust-analyzer cargo strfmt 0.2.4 types/Sign#Plus# |
| 363 | } |
| 364 | |
| 365 | /// sign minus getter |
| 366 | /// here because it is in fmt::Formatter |
| 367 | pub fn sign_minusrust-analyzer cargo strfmt 0.2.4 formatter/impl#[`Formatter<'a, 'b>`]sign_minus().(&self) -> bool { |
| 368 | self.signrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#sign. rust-analyzer cargo strfmt 0.2.4 types/impl#[Sign][`PartialEq<Self>`]eq().==rust-analyzer cargo strfmt 0.2.4 types/impl#[Sign][`PartialEq<Self>`]eq(). rust-analyzer cargo strfmt 0.2.4 types/impl#[Sign][`PartialEq<Self>`]eq().Signrust-analyzer cargo strfmt 0.2.4 types/Sign#::Minusrust-analyzer cargo strfmt 0.2.4 types/Sign#Minus# |
| 369 | } |
| 370 | |
| 371 | /// alternate getter |
| 372 | pub fn alternaterust-analyzer cargo strfmt 0.2.4 formatter/impl#[`Formatter<'a, 'b>`]alternate().(&self) -> bool { |
| 373 | self.alternaterust-analyzer cargo strfmt 0.2.4 formatter/Formatter#alternate. |
| 374 | } |
| 375 | |
| 376 | // sign_aware_zero_pad // Not supported |
| 377 | |
| 378 | /// type getter |
| 379 | pub fn tyrust-analyzer cargo strfmt 0.2.4 formatter/impl#[`Formatter<'a, 'b>`]ty().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<char> { |
| 380 | self.tyrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#ty. |
| 381 | } |
| 382 | |
| 383 | /// UNSTABLE: in the future, this may return true if all validty |
| 384 | /// checks for a float return true |
| 385 | /// return true if ty is valid for formatting integers |
| 386 | pub fn is_int_typerust-analyzer cargo strfmt 0.2.4 formatter/impl#[`Formatter<'a, 'b>`]is_int_type().(&self) -> bool { |
| 387 | match self.tyrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#ty. { |
| 388 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => true, |
| 389 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c) => match c { |
| 390 | 'b' | 'o' | 'x' | 'X' => true, |
| 391 | _ => false, |
| 392 | }, |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | /// UNSTABLE: in the future, this may return true if all validty |
| 397 | /// checks for a float return true |
| 398 | /// return true if ty is valid for formatting floats |
| 399 | pub fn is_float_typerust-analyzer cargo strfmt 0.2.4 formatter/impl#[`Formatter<'a, 'b>`]is_float_type().(&self) -> bool { |
| 400 | match self.tyrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#ty. { |
| 401 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => true, |
| 402 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c) => match c { |
| 403 | 'f' | 'e' | 'E' => true, |
| 404 | _ => false, |
| 405 | }, |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | impl<'a, 'b> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write# for Formatterrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#<'a, 'b> { |
| 411 | fn write_strrust-analyzer cargo strfmt 0.2.4 formatter/impl#[`Formatter<'a, 'b>`][Write]write_str().(&mut self, s: &str) -> 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# { |
| 412 | self.buffrust-analyzer cargo strfmt 0.2.4 formatter/Formatter#buff..write_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Write]write_str().(s) |
| 413 | } |
| 414 | } |