Debian Codegraph @

debian/missing-sources/jiff/src/shared/util/array_str.rs

raw symbols SCIP
1 /// A simple and not the most-efficient fixed size string on the stack.
2 ///
3 /// This supplanted some uses of `Box<str>` for storing tiny strings in an
4 /// effort to reduce our dependence on dynamic memory allocation.
5 ///
6 /// Also, since it isn't needed and it lets us save on storage requirements,
7 /// `N` must be less than `256` (so that the length can fit in a `u8`).
8 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:)]
9 #[doc(hidden)] // not part of Jiff's public API
10 pub struct ArrayStrrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#<const N: usize> {
11 /// The UTF-8 bytes that make up the string.
12 ///
13 /// This array---the entire array---is always valid UTF-8. And
14 /// the `0..self.len` sub-slice is also always valid UTF-8.
15 bytesrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#bytes.: [u8; N],
16 /// The number of bytes used by the string in `bytes`.
17 ///
18 /// (We could technically save this byte in some cases and use a NUL
19 /// terminator. For example, since we don't permit NUL bytes in POSIX time
20 /// zone abbreviation strings, but this is simpler and only one byte and
21 /// generalizes. And we're not really trying to micro-optimize the storage
22 /// requirements when we use these array strings. Or at least, I don't know
23 /// of a reason to.)
24 lenrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#len.: u8,
25 }
26
27 impl<const N: usize> ArrayStrrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#<N> {
28 /// Creates a new fixed capacity string.
29 ///
30 /// If the given string exceeds `N` bytes, then this returns
31 /// `None`.
32 pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn newrust-analyzer cargo jiff 0.2.18 shared/util/array_str/impl#[`ArrayStr<N>`]new().(s: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ArrayStrrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#<N>> {
33 let len = s.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().();
34 if len 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().N {
35 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
36 }
37 let mut bytes = [0; N];
38 let mut i = 0;
39 while i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().s.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() {
40 bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut(). = s.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
41 i 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;
42 }
43 // OK because we don't ever use anything bigger than u8::MAX for `N`.
44 // And we probably shouldn't, because that would be a pretty chunky
45 // array. If such a thing is needed, please file an issue to discuss.
46 debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(N <= u8::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]MAX. as usize, "size of ArrayStr is too big");
47 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ArrayStrrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr# { bytesrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#bytes., lenrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#len.: len as u8 })
48 }
49
50 /// Returns the capacity of this array string.
51 pub(craterust-analyzer cargo jiff 0.2.18 crate/) fn capacityrust-analyzer cargo jiff 0.2.18 shared/util/array_str/impl#[`ArrayStr<N>`]capacity().() -> usize {
52 N
53 }
54
55 /// Append the bytes given to the end of this string.
56 ///
57 /// If the capacity would be exceeded, then this is a no-op and `false`
58 /// is returned.
59 pub(craterust-analyzer cargo jiff 0.2.18 crate/) fn push_strrust-analyzer cargo jiff 0.2.18 shared/util/array_str/impl#[`ArrayStr<N>`]push_str().(&mut self, s: &str) -> bool {
60 let len = usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u8>`]from().(self.lenrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#len.);
61 let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(new_len) = len.checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(s.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()) else { return false };
62 if new_len 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().N {
63 return false;
64 }
65 self.bytesrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#bytes.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().len..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#new_len]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut()..copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(s.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().());
66 // OK because we don't ever use anything bigger than u8::MAX for `N`.
67 // And we probably shouldn't, because that would be a pretty chunky
68 // array. If such a thing is needed, please file an issue to discuss.
69 debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(
70 N <= usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u8>`]from().(u8::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]MAX.),
71 "size of ArrayStr is too big"
72 );
73 self.lenrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#len. = u8::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[u8][`TryFrom<usize>`]try_from().(new_len).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
74 true
75 }
76
77 /// Returns this array string as a string slice.
78 pub(craterust-analyzer cargo jiff 0.2.18 crate/) fn as_strrust-analyzer cargo jiff 0.2.18 shared/util/array_str/impl#[`ArrayStr<N>`]as_str().(&self) -> &str {
79 // OK because construction guarantees valid UTF-8.
80 //
81 // This is bullet proof enough to use unchecked `str` construction
82 // here, but I can't dream up of a benchmark where it matters.
83 corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&self.bytesrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#bytes.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u8>`]from().(self.lenrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#len.)]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
84 }
85 }
86
87 /// Easy construction of `ArrayStr` from `&'static str`.
88 ///
89 /// We specifically limit to `&'static str` to approximate string literals.
90 /// This prevents most cases of accidentally creating a non-string literal
91 /// that panics if the string is too big.
92 ///
93 /// This impl primarily exists to make writing tests more convenient.
94 impl<const N: usize> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'static str> for ArrayStrrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#<N> {
95 fn fromrust-analyzer cargo jiff 0.2.18 shared/util/array_str/impl#[`ArrayStr<N>`][`From<&'static str>`]from().(s: &'static str) -> ArrayStrrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#<N> {
96 ArrayStrrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#::newrust-analyzer cargo jiff 0.2.18 shared/util/array_str/impl#[`ArrayStr<N>`]new().(s).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
97 }
98 }
99
100 impl<const N: usize> PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<str> for ArrayStrrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#<N> {
101 fn eqrust-analyzer cargo jiff 0.2.18 shared/util/array_str/impl#[`ArrayStr<N>`][`PartialEq<str>`]eq().(&self, rhs: &str) -> bool {
102 self.as_strrust-analyzer cargo jiff 0.2.18 shared/util/array_str/impl#[`ArrayStr<N>`]as_str().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().rhs
103 }
104 }
105
106 impl<const N: usize> PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<&str> for ArrayStrrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#<N> {
107 fn eqrust-analyzer cargo jiff 0.2.18 shared/util/array_str/impl#[`ArrayStr<N>`][`PartialEq<&str>`]eq().(&self, rhs: &&str) -> bool {
108 self.as_strrust-analyzer cargo jiff 0.2.18 shared/util/array_str/impl#[`ArrayStr<N>`]as_str().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().rhs
109 }
110 }
111
112 impl<const N: usize> PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<ArrayStrrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#<N>> for str {
113 fn eqrust-analyzer cargo jiff 0.2.18 shared/util/array_str/impl#[str][`PartialEq<ArrayStr<N>>`]eq().(&self, rhs: &ArrayStrrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#<N>) -> bool {
114 self rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().rhs.as_strrust-analyzer cargo jiff 0.2.18 shared/util/array_str/impl#[`ArrayStr<N>`]as_str().()
115 }
116 }
117
118 impl<const N: usize> 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/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for ArrayStrrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#<N> {
119 fn fmtrust-analyzer cargo jiff 0.2.18 shared/util/array_str/impl#[`ArrayStr<N>`][Debug]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# {
120 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/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[str][Debug]fmt().(self.as_strrust-analyzer cargo jiff 0.2.18 shared/util/array_str/impl#[`ArrayStr<N>`]as_str().(), f)
121 }
122 }
123
124 impl<const N: usize> 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# for ArrayStrrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#<N> {
125 fn fmtrust-analyzer cargo jiff 0.2.18 shared/util/array_str/impl#[`ArrayStr<N>`][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# {
126 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#::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[str][Display]fmt().(self.as_strrust-analyzer cargo jiff 0.2.18 shared/util/array_str/impl#[`ArrayStr<N>`]as_str().(), f)
127 }
128 }
129
130 impl<const N: usize> 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# for ArrayStrrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#<N> {
131 fn write_strrust-analyzer cargo jiff 0.2.18 shared/util/array_str/impl#[`ArrayStr<N>`][Write]write_str().(&mut self, s: &str) -> 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# {
132 if self.push_strrust-analyzer cargo jiff 0.2.18 shared/util/array_str/impl#[`ArrayStr<N>`]push_str().(s) {
133 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
134 } else {
135 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(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/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Error#)
136 }
137 }
138 }
139
140 impl<const N: usize> AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str> for ArrayStrrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#<N> {
141 fn as_refrust-analyzer cargo jiff 0.2.18 shared/util/array_str/impl#[`ArrayStr<N>`][`AsRef<str>`]as_ref().(&self) -> &str {
142 self.as_strrust-analyzer cargo jiff 0.2.18 shared/util/array_str/impl#[`ArrayStr<N>`]as_str().()
143 }
144 }
145
146 /// A self-imposed limit on the size of a time zone abbreviation, in bytes.
147 ///
148 /// POSIX says this:
149 ///
150 /// > Indicate no less than three, nor more than {TZNAME_MAX}, bytes that are
151 /// > the designation for the standard (std) or the alternative (dst -such as
152 /// > Daylight Savings Time) timezone.
153 ///
154 /// But it doesn't seem worth the trouble to query `TZNAME_MAX`. Interestingly,
155 /// IANA says:
156 ///
157 /// > are 3 or more characters specifying the standard and daylight saving time
158 /// > (DST) zone abbreviations
159 ///
160 /// Which implies that IANA thinks there is no limit. But that seems unwise.
161 /// Moreover, in practice, it seems like the `date` utility supports fairly
162 /// long abbreviations. On my mac (so, BSD `date` as I understand it):
163 ///
164 /// ```text
165 /// $ TZ=ZZZ5YYYYYYYYYYYYYYYYYYYYY date
166 /// Sun Mar 17 20:05:58 YYYYYYYYYYYYYYYYYYYYY 2024
167 /// ```
168 ///
169 /// And on my Linux machine (so, GNU `date`):
170 ///
171 /// ```text
172 /// $ TZ=ZZZ5YYYYYYYYYYYYYYYYYYYYY date
173 /// Sun Mar 17 08:05:36 PM YYYYYYYYYYYYYYYYYYYYY 2024
174 /// ```
175 ///
176 /// I don't know exactly what limit these programs use, but 30 seems good
177 /// enough?
178 ///
179 /// (Previously, I had been using 255 and stuffing the string in a `Box<str>`.
180 /// But as part of work on [#168], I was looking to remove allocation from as
181 /// many places as possible. And this was one candidate. But making room on the
182 /// stack for 255 byte abbreviations seemed gratuitous. So I picked something
183 /// smaller. If we come across an abbreviation bigger than this max, then we'll
184 /// error.)
185 ///
186 /// [#168]: https://github.com/BurntSushi/jiff/issues/168
187 const ABBREVIATION_MAXrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ABBREVIATION_MAX.: usize = 30;
188
189 /// A type alias for centralizing the definition of a time zone abbreviation.
190 ///
191 /// Basically, this creates one single coherent place where we control the
192 /// length of a time zone abbreviation.
193 #[doc(hidden)] // not part of Jiff's public API
194 pub type Abbreviationrust-analyzer cargo jiff 0.2.18 shared/util/array_str/Abbreviation# = ArrayStrrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#<ABBREVIATION_MAXrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ABBREVIATION_MAX.>;
195
196 #[cfg(test)]
197 mod tests {
198 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#;
199
200 use superrust-analyzer cargo jiff 0.2.18 shared/util/::*;
201
202 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
203 fn fmt_write() {
204 let mut dst = ArrayStrrust-analyzer cargo jiff 0.2.18 shared/util/array_str/ArrayStr#::<5>::new("").unwrap();
205 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(write!(&mut dst, "abcd").is_ok());
206 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(write!(&mut dst, "e").is_ok());
207 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(write!(&mut dst, "f").is_err());
208 }
209 }