Debian Codegraph @

debian/missing-sources/string_cache/src/atom.rs

raw symbols SCIP
1 // Copyright 2014 The Servo Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 use craterust-analyzer cargo string_cache 0.9.0 crate/::dynamic_setrust-analyzer cargo string_cache 0.9.0 dynamic_set/::{dynamic_setrust-analyzer cargo string_cache 0.9.0 dynamic_set/dynamic_set()., Entryrust-analyzer cargo string_cache 0.9.0 dynamic_set/Entry#};
11 use craterust-analyzer cargo string_cache 0.9.0 crate/::static_setsrust-analyzer cargo string_cache 0.9.0 static_sets/::StaticAtomSetrust-analyzer cargo string_cache 0.9.0 static_sets/StaticAtomSet#;
12 use debug_unreachablerust-analyzer cargo new_debug_unreachable 1.0.6 crate/::debug_unreachablerust-analyzer cargo new_debug_unreachable 1.0.6 debug_unreachable!;
13
14 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#;
15 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#::{selfrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#, Equalrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Equal#};
16 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/;
17 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::hashrust-analyzer cargo std https://github.com/rust-lang/rust/library/std hash/::{Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#, Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#};
18 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#;
19 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/;
20 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::numrust-analyzer cargo std https://github.com/rust-lang/rust/library/std num/::NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#;
21 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/;
22 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/;
23 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/;
24 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::atomicrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::SeqCstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#SeqCst#;
25
26 const DYNAMIC_TAGrust-analyzer cargo string_cache 0.9.0 atom/DYNAMIC_TAG.: u8 = 0b_00;
27 const INLINE_TAGrust-analyzer cargo string_cache 0.9.0 atom/INLINE_TAG.: u8 = 0b_01; // len in upper nybble
28 const STATIC_TAGrust-analyzer cargo string_cache 0.9.0 atom/STATIC_TAG.: u8 = 0b_10;
29 const TAG_MASKrust-analyzer cargo string_cache 0.9.0 atom/TAG_MASK.: u64 = 0b_11;
30 const LEN_OFFSETrust-analyzer cargo string_cache 0.9.0 atom/LEN_OFFSET.: u64 = 4;
31 const LEN_MASKrust-analyzer cargo string_cache 0.9.0 atom/LEN_MASK.: u64 = 0xF0;
32
33 const MAX_INLINE_LENrust-analyzer cargo string_cache 0.9.0 atom/MAX_INLINE_LEN.: usize = 7;
34 const STATIC_SHIFT_BITSrust-analyzer cargo string_cache 0.9.0 atom/STATIC_SHIFT_BITS.: usize = 32;
35
36 /// Represents a string that has been interned.
37 ///
38 /// While the type definition for `Atom` indicates that it generic on a particular
39 /// implementation of an atom set, you don't need to worry about this. Atoms can be static
40 /// and come from a `StaticAtomSet` generated by the `string_cache_codegen` crate, or they
41 /// can be dynamic and created by you on an `EmptyStaticAtomSet`.
42 ///
43 /// `Atom` implements `Clone` but not `Copy`, since internally atoms are reference-counted;
44 /// this means that you may need to `.clone()` an atom to keep copies to it in different
45 /// places, or when passing it to a function that takes an `Atom` rather than an `&Atom`.
46 ///
47 /// ## Creating an atom at runtime
48 ///
49 /// If you use `string_cache_codegen` to generate a precomputed list of atoms, your code
50 /// may then do something like read data from somewhere and extract tokens that need to be
51 /// compared to the atoms. In this case, you can use `Atom::from(&str)` or
52 /// `Atom::from(String)`. These create a reference-counted atom which will be
53 /// automatically freed when all references to it are dropped.
54 ///
55 /// This means that your application can safely have a loop which tokenizes data, creates
56 /// atoms from the tokens, and compares the atoms to a predefined set of keywords, without
57 /// running the risk of arbitrary memory consumption from creating large numbers of atoms —
58 /// as long as your application does not store clones of the atoms it creates along the
59 /// way.
60 ///
61 /// For example, the following is safe and will not consume arbitrary amounts of memory:
62 ///
63 /// ```ignore
64 /// let untrusted_data = "large amounts of text ...";
65 ///
66 /// for token in untrusted_data.split_whitespace() {
67 /// let atom = Atom::from(token); // interns the string
68 ///
69 /// if atom == Atom::from("keyword") {
70 /// // handle that keyword
71 /// } else if atom == Atom::from("another_keyword") {
72 /// // handle that keyword
73 /// } else {
74 /// println!("unknown keyword");
75 /// }
76 /// } // atom is dropped here, so it is not kept around in memory
77 /// ```
78 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
79 // NOTE: Deriving PartialEq requires that a given string must always be interned the same way.
80 pub struct Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom#<Static> {
81 unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/Atom#unsafe_data.: NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#,
82 phantomrust-analyzer cargo string_cache 0.9.0 atom/Atom#phantom.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<Static>,
83 }
84
85 // This isn't really correct as the Atoms can technically take up space. But I guess it's ok
86 // as it is possible to measure the size of the atom set separately/
87 #[cfg(feature = "malloc_size_of")]
88 impl<Static: StaticAtomSetrust-analyzer cargo string_cache 0.9.0 static_sets/StaticAtomSet#> malloc_size_of::MallocSizeOf for Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom#<Static> {
89 fn size_of(&self, _ops: &mut malloc_size_of::MallocSizeOfOps) -> usize {
90 0
91 }
92 }
93
94 // FIXME: bound removed from the struct definition before of this error for pack_static:
95 // "error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable"
96 // https://github.com/rust-lang/rust/issues/57563
97 impl<Static> Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom#<Static> {
98 /// For the atom!() macros
99 #[inline(always)]
100 #[doc(hidden)]
101 pub const fn pack_staticrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]pack_static().(n: u32) -> Selfrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`] {
102 Selfrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`] {
103 unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/Atom#unsafe_data.: unsafe {
104 // STATIC_TAG ensures this is non-zero
105 NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#::new_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]new_unchecked().((STATIC_TAGrust-analyzer cargo string_cache 0.9.0 atom/STATIC_TAG. as u64) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor().((n as u64) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<usize>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<usize>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<usize>`]shl().STATIC_SHIFT_BITSrust-analyzer cargo string_cache 0.9.0 atom/STATIC_SHIFT_BITS.))
106 },
107 phantomrust-analyzer cargo string_cache 0.9.0 atom/Atom#phantom.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#,
108 }
109 }
110
111 /// For the atom!() macros
112 #[inline(always)]
113 #[doc(hidden)]
114 pub const fn pack_inlinerust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]pack_inline().(mut n: u64, len: u8) -> Selfrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`] {
115 if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_endian = "big") {
116 // Reverse order of top 7 bytes.
117 // Bottom 8 bits of `n` are zero, and we need that to remain so.
118 // String data is stored in top 7 bytes, tag and length in bottom byte.
119 n = n.to_lerust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]to_le().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<i32>`]shl().8;
120 }
121
122 let data: u64 = (INLINE_TAGrust-analyzer cargo string_cache 0.9.0 atom/INLINE_TAG. as u64) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor().((len as u64) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<Self>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<Self>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<Self>`]shl().LEN_OFFSETrust-analyzer cargo string_cache 0.9.0 atom/LEN_OFFSET.) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor().n;
123 Selfrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`] {
124 // INLINE_TAG ensures this is never zero
125 unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/Atom#unsafe_data.: unsafe { NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#::new_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]new_unchecked().(data) },
126 phantomrust-analyzer cargo string_cache 0.9.0 atom/Atom#phantom.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#,
127 }
128 }
129
130 fn tagrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]tag().(&self) -> u8 {
131 (self.unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/Atom#unsafe_data..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]get().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().TAG_MASKrust-analyzer cargo string_cache 0.9.0 atom/TAG_MASK.) as u8
132 }
133 }
134
135 impl<Static: StaticAtomSetrust-analyzer cargo string_cache 0.9.0 static_sets/StaticAtomSet#> Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom#<Static> {
136 /// Return the internal representation. For testing.
137 #[doc(hidden)]
138 pub fn unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]unsafe_data().(&self) -> u64 {
139 self.unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/Atom#unsafe_data..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]get().()
140 }
141
142 /// Return true if this is a static Atom. For testing.
143 #[doc(hidden)]
144 pub fn is_staticrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]is_static().(&self) -> bool {
145 self.tagrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]tag().() 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().STATIC_TAGrust-analyzer cargo string_cache 0.9.0 atom/STATIC_TAG.
146 }
147
148 /// Return true if this is a dynamic Atom. For testing.
149 #[doc(hidden)]
150 pub fn is_dynamicrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]is_dynamic().(&self) -> bool {
151 self.tagrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]tag().() 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().DYNAMIC_TAGrust-analyzer cargo string_cache 0.9.0 atom/DYNAMIC_TAG.
152 }
153
154 /// Return true if this is an inline Atom. For testing.
155 #[doc(hidden)]
156 pub fn is_inlinerust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]is_inline().(&self) -> bool {
157 self.tagrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]tag().() 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().INLINE_TAGrust-analyzer cargo string_cache 0.9.0 atom/INLINE_TAG.
158 }
159
160 fn static_indexrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]static_index().(&self) -> u64 {
161 self.unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/Atom#unsafe_data..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]get().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<usize>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<usize>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<usize>`]shr().STATIC_SHIFT_BITSrust-analyzer cargo string_cache 0.9.0 atom/STATIC_SHIFT_BITS.
162 }
163
164 /// Get the hash of the string as it is stored in the set.
165 pub fn get_hashrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]get_hash().(&self) -> u32 {
166 match self.tagrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]tag().() {
167 DYNAMIC_TAGrust-analyzer cargo string_cache 0.9.0 atom/DYNAMIC_TAG. => {
168 let entry = self.unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/Atom#unsafe_data..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]get().() as *const Entryrust-analyzer cargo string_cache 0.9.0 dynamic_set/Entry#;
169 unsafe { (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().entry).hashrust-analyzer cargo string_cache 0.9.0 dynamic_set/Entry#hash. }
170 }
171 STATIC_TAGrust-analyzer cargo string_cache 0.9.0 atom/STATIC_TAG. => Static::getrust-analyzer cargo string_cache 0.9.0 static_sets/StaticAtomSet#get().().hashesrust-analyzer cargo string_cache 0.9.0 static_sets/PhfStrSet#hashes.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().self.static_indexrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]static_index().() as usize]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
172 INLINE_TAGrust-analyzer cargo string_cache 0.9.0 atom/INLINE_TAG. => {
173 let data = self.unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/Atom#unsafe_data..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]get().();
174 // This may or may not be great...
175 ((data rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr().32) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitXor<Self>`]bitxor().^rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitXor<Self>`]bitxor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitXor<Self>`]bitxor().data) as u32
176 }
177 _ => unsafe { debug_unreachablerust-analyzer cargo new_debug_unreachable 1.0.6 debug_unreachable!!() },
178 }
179 }
180
181 pub fn try_staticrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]try_static().(string_to_add: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]> {
182 Selfrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]::try_static_internalrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]try_static_internal().(string_to_add).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()
183 }
184
185 fn try_static_internalrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]try_static_internal().(string_to_add: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`], phf_sharedrust-analyzer cargo phf_shared 0.13.1 crate/::Hashesrust-analyzer cargo phf_shared 0.13.1 Hashes#> {
186 let static_set = Static::getrust-analyzer cargo string_cache 0.9.0 static_sets/StaticAtomSet#get().();
187 let hash = phf_sharedrust-analyzer cargo phf_shared 0.13.1 crate/::hashrust-analyzer cargo phf_shared 0.13.1 hash().(&*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().string_to_add, &static_set.keyrust-analyzer cargo string_cache 0.9.0 static_sets/PhfStrSet#key.);
188 let index = phf_sharedrust-analyzer cargo phf_shared 0.13.1 crate/::get_indexrust-analyzer cargo phf_shared 0.13.1 get_index().(&hash, static_set.dispsrust-analyzer cargo string_cache 0.9.0 static_sets/PhfStrSet#disps., static_set.atomsrust-analyzer cargo string_cache 0.9.0 static_sets/PhfStrSet#atoms..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().());
189
190 if static_set.atomsrust-analyzer cargo string_cache 0.9.0 static_sets/PhfStrSet#atoms.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().index as usize]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#[`&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().string_to_add {
191 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]::pack_staticrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]pack_static().(index))
192 } else {
193 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(hash)
194 }
195 }
196 }
197
198 impl<Static: StaticAtomSetrust-analyzer cargo string_cache 0.9.0 static_sets/StaticAtomSet#> Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom#<Static> {
199 #[inline]
200 fn defaultrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][Default]default().() -> Selfrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][Default] {
201 Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom#::pack_staticrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]pack_static().(Static::empty_string_indexrust-analyzer cargo string_cache 0.9.0 static_sets/StaticAtomSet#empty_string_index().())
202 }
203 }
204
205 impl<Static: StaticAtomSetrust-analyzer cargo string_cache 0.9.0 static_sets/StaticAtomSet#> Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# for Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom#<Static> {
206 #[inline]
207 fn hashrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][Hash]hash().<H>(&self, state: &mut H)
208 where
209 H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#,
210 {
211 state.write_u32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#write_u32().(self.get_hashrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]get_hash().())
212 }
213 }
214
215 impl<'a, Static: StaticAtomSetrust-analyzer cargo string_cache 0.9.0 static_sets/StaticAtomSet#> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, str>> for Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom#<Static> {
216 fn fromrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][`From<Cow<'a, str>>`]from().(string_to_add: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, str>) -> Selfrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][`From<Cow<'a, str>>`] {
217 let len = string_to_add.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().();
218 if len 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 {
219 Selfrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][`From<Cow<'a, str>>`]::pack_staticrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]pack_static().(Static::empty_string_indexrust-analyzer cargo string_cache 0.9.0 static_sets/StaticAtomSet#empty_string_index().())
220 } else if len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().MAX_INLINE_LENrust-analyzer cargo string_cache 0.9.0 atom/MAX_INLINE_LEN. {
221 let mut data: u64 = (INLINE_TAGrust-analyzer cargo string_cache 0.9.0 atom/INLINE_TAG. as u64) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor().((len as u64) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<Self>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<Self>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<Self>`]shl().LEN_OFFSETrust-analyzer cargo string_cache 0.9.0 atom/LEN_OFFSET.);
222 {
223 let dest = inline_atom_slice_mutrust-analyzer cargo string_cache 0.9.0 atom/inline_atom_slice_mut().(&mut data);
224 dest[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#len]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()..copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(string_to_add.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().());
225 }
226 Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom# {
227 // INLINE_TAG ensures this is never zero
228 unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/Atom#unsafe_data.: unsafe { NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#::new_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]new_unchecked().(data) },
229 phantomrust-analyzer cargo string_cache 0.9.0 atom/Atom#phantom.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#,
230 }
231 } else {
232 Selfrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][`From<Cow<'a, str>>`]::try_static_internalrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]try_static_internal().(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`][Deref]deref().string_to_add).unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(|hash| {
233 let ptr: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::NonNullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/non_null/NonNull#<Entryrust-analyzer cargo string_cache 0.9.0 dynamic_set/Entry#> = dynamic_setrust-analyzer cargo string_cache 0.9.0 dynamic_set/dynamic_set().().insertrust-analyzer cargo string_cache 0.9.0 dynamic_set/impl#[Set]insert().(string_to_add, hash.grust-analyzer cargo phf_shared 0.13.1 Hashes#g.);
234 let data = ptr.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/non_null/impl#[`NonNull<T>`]as_ptr().() as u64;
235 debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(0 == data &rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand(). TAG_MASKrust-analyzer cargo string_cache 0.9.0 atom/TAG_MASK.);
236 Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom# {
237 // The address of a ptr::NonNull is non-zero
238 unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/Atom#unsafe_data.: unsafe { NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#::new_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]new_unchecked().(data) },
239 phantomrust-analyzer cargo string_cache 0.9.0 atom/Atom#phantom.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#,
240 }
241 })
242 }
243 }
244 }
245
246 impl<Static: StaticAtomSetrust-analyzer cargo string_cache 0.9.0 static_sets/StaticAtomSet#> Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom#<Static> {
247 #[inline(always)]
248 fn clonerust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][Clone]clone().(&self) -> Selfrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][Clone] {
249 if self.tagrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]tag().() 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().DYNAMIC_TAGrust-analyzer cargo string_cache 0.9.0 atom/DYNAMIC_TAG. {
250 let entry = self.unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/Atom#unsafe_data..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]get().() as *const Entryrust-analyzer cargo string_cache 0.9.0 dynamic_set/Entry#;
251 unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().entry }.ref_countrust-analyzer cargo string_cache 0.9.0 dynamic_set/Entry#ref_count..fetch_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicIsize]fetch_add().(1, SeqCstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#SeqCst#);
252 }
253 Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom# { ..*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self }
254 }
255 }
256
257 impl<Static> Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom#<Static> {
258 #[inline]
259 fn droprust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][Drop]drop().(&mut self) {
260 if self.tagrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]tag().() 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().DYNAMIC_TAGrust-analyzer cargo string_cache 0.9.0 atom/DYNAMIC_TAG. {
261 let entry = self.unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/Atom#unsafe_data..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]get().() as *const Entryrust-analyzer cargo string_cache 0.9.0 dynamic_set/Entry#;
262 if unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().entry }.ref_countrust-analyzer cargo string_cache 0.9.0 dynamic_set/Entry#ref_count..fetch_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicIsize]fetch_sub().(1, SeqCstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#SeqCst#) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]eq().1 {
263 drop_slowrust-analyzer cargo string_cache 0.9.0 atom/drop_slow().(self)
264 }
265 }
266
267 // Out of line to guide inlining.
268 fn drop_slowrust-analyzer cargo string_cache 0.9.0 atom/drop_slow().<Static>(this: &mut Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom#<Static>) {
269 dynamic_setrust-analyzer cargo string_cache 0.9.0 dynamic_set/dynamic_set().().removerust-analyzer cargo string_cache 0.9.0 dynamic_set/impl#[Set]remove().(this.unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/Atom#unsafe_data..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]get().() as *mut Entryrust-analyzer cargo string_cache 0.9.0 dynamic_set/Entry#);
270 }
271 }
272 }
273
274 impl<Static: StaticAtomSetrust-analyzer cargo string_cache 0.9.0 static_sets/StaticAtomSet#> opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref# for Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom#<Static> {
275 type Targetrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][Deref]Target# = str;
276
277 #[inline]
278 fn derefrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][Deref]deref().(&self) -> &str {
279 unsafe {
280 match self.tagrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]tag().() {
281 DYNAMIC_TAGrust-analyzer cargo string_cache 0.9.0 atom/DYNAMIC_TAG. => {
282 let entry = self.unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/Atom#unsafe_data..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]get().() as *const Entryrust-analyzer cargo string_cache 0.9.0 dynamic_set/Entry#;
283 &(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().entry).stringrust-analyzer cargo string_cache 0.9.0 dynamic_set/Entry#string.
284 }
285 INLINE_TAGrust-analyzer cargo string_cache 0.9.0 atom/INLINE_TAG. => {
286 let len = (self.unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]unsafe_data().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().LEN_MASKrust-analyzer cargo string_cache 0.9.0 atom/LEN_MASK.) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<Self>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<Self>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<Self>`]shr().LEN_OFFSETrust-analyzer cargo string_cache 0.9.0 atom/LEN_OFFSET.;
287 debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(len as usize <= MAX_INLINE_LENrust-analyzer cargo string_cache 0.9.0 atom/MAX_INLINE_LEN.);
288 let src = inline_atom_slicerust-analyzer cargo string_cache 0.9.0 atom/inline_atom_slice().(&self.unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/Atom#unsafe_data.);
289 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().(src.get_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_unchecked().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#(len as usize)))
290 }
291 STATIC_TAGrust-analyzer cargo string_cache 0.9.0 atom/STATIC_TAG. => Static::getrust-analyzer cargo string_cache 0.9.0 static_sets/StaticAtomSet#get().().atomsrust-analyzer cargo string_cache 0.9.0 static_sets/PhfStrSet#atoms.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().self.static_indexrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]static_index().() as usize]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
292 _ => debug_unreachablerust-analyzer cargo new_debug_unreachable 1.0.6 debug_unreachable!!(),
293 }
294 }
295 }
296 }
297
298 impl<Static: StaticAtomSetrust-analyzer cargo string_cache 0.9.0 static_sets/StaticAtomSet#> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom#<Static> {
299 #[inline]
300 fn fmtrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][Debug]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# {
301 let ty_str = unsafe {
302 match self.tagrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]tag().() {
303 DYNAMIC_TAGrust-analyzer cargo string_cache 0.9.0 atom/DYNAMIC_TAG. => "dynamic",
304 INLINE_TAGrust-analyzer cargo string_cache 0.9.0 atom/INLINE_TAG. => "inline",
305 STATIC_TAGrust-analyzer cargo string_cache 0.9.0 atom/STATIC_TAG. => "static",
306 _ => debug_unreachablerust-analyzer cargo new_debug_unreachable 1.0.6 debug_unreachable!!(),
307 }
308 };
309
310 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Atom('{}' type={})", &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self, ty_str)
311 }
312 }
313
314 impl<Static: StaticAtomSetrust-analyzer cargo string_cache 0.9.0 static_sets/StaticAtomSet#> PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd# for Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom#<Static> {
315 #[inline]
316 fn partial_cmprust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][`PartialOrd<Self>`]partial_cmp().(&self, other: &Selfrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][`PartialOrd<Self>`]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#> {
317 if self.unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/Atom#unsafe_data. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`][`PartialEq<Self>`]eq().other.unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/Atom#unsafe_data. {
318 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Equalrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Equal#);
319 }
320 self.as_refrust-analyzer cargo string_cache 0.9.0 trivial_impls/impl#[`Atom<Static>`][`AsRef<str>`]as_ref().().partial_cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/impl#[str][`PartialOrd<Self>`]partial_cmp().(other.as_refrust-analyzer cargo string_cache 0.9.0 trivial_impls/impl#[`Atom<Static>`][`AsRef<str>`]as_ref().())
321 }
322 }
323
324 impl<Static: StaticAtomSetrust-analyzer cargo string_cache 0.9.0 static_sets/StaticAtomSet#> Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord# for Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom#<Static> {
325 #[inline]
326 fn cmprust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][Ord]cmp().(&self, other: &Selfrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][Ord]) -> Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering# {
327 if self.unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/Atom#unsafe_data. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`][`PartialEq<Self>`]eq().other.unsafe_datarust-analyzer cargo string_cache 0.9.0 atom/Atom#unsafe_data. {
328 return Equalrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#Equal#;
329 }
330 self.as_refrust-analyzer cargo string_cache 0.9.0 trivial_impls/impl#[`Atom<Static>`][`AsRef<str>`]as_ref().().cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/impl#[str][Ord]cmp().(other.as_refrust-analyzer cargo string_cache 0.9.0 trivial_impls/impl#[`Atom<Static>`][`AsRef<str>`]as_ref().())
331 }
332 }
333
334 // AsciiExt requires mutating methods, so we just implement the non-mutating ones.
335 // We don't need to implement is_ascii because there's no performance improvement
336 // over the one from &str.
337 impl<Static: StaticAtomSetrust-analyzer cargo string_cache 0.9.0 static_sets/StaticAtomSet#> Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom#<Static> {
338 fn from_mutated_strrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]from_mutated_str().<F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(&mut str)>(s: &str, f: F) -> Selfrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`] {
339 let mut buffer = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#::<[u8; 64]>::uninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]uninit().();
340 let buffer = unsafe { &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().buffer.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/impl#[`MaybeUninit<T>`]as_mut_ptr().() };
341
342 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(buffer_prefix) = buffer.get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_mut().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#s.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()) {
343 buffer_prefix.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().());
344 let as_str = unsafe { ::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/::from_utf8_unchecked_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8_unchecked_mut().(buffer_prefix) };
345 f(as_str);
346 Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom#::fromrust-analyzer cargo string_cache 0.9.0 trivial_impls/impl#[`Atom<Static>`][`From<&'a str>`]from().(&*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().as_str)
347 } else {
348 let mut string = s.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().();
349 f(&mut string);
350 Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom#::fromrust-analyzer cargo string_cache 0.9.0 trivial_impls/impl#[`Atom<Static>`][`From<String>`]from().(string)
351 }
352 }
353
354 /// Like [`to_ascii_uppercase`].
355 ///
356 /// [`to_ascii_uppercase`]: https://doc.rust-lang.org/std/ascii/trait.AsciiExt.html#tymethod.to_ascii_uppercase
357 pub fn to_ascii_uppercaserust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]to_ascii_uppercase().(&self) -> Selfrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`] {
358 for (i, b) in self.bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]bytes().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
359 if let b'a'..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#b'z' = b {
360 return Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom#::from_mutated_strrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]from_mutated_str().(self, |s| s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().i..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()..make_ascii_uppercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]make_ascii_uppercase().());
361 }
362 }
363 self.clonerust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][Clone]clone().()
364 }
365
366 /// Like [`to_ascii_lowercase`].
367 ///
368 /// [`to_ascii_lowercase`]: https://doc.rust-lang.org/std/ascii/trait.AsciiExt.html#tymethod.to_ascii_lowercase
369 pub fn to_ascii_lowercaserust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]to_ascii_lowercase().(&self) -> Selfrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`] {
370 for (i, b) in self.bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]bytes().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
371 if let b'A'..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#b'Z' = b {
372 return Atomrust-analyzer cargo string_cache 0.9.0 atom/Atom#::from_mutated_strrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]from_mutated_str().(self, |s| s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().i..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut()..make_ascii_lowercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]make_ascii_lowercase().());
373 }
374 }
375 self.clonerust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][Clone]clone().()
376 }
377
378 /// Like [`eq_ignore_ascii_case`].
379 ///
380 /// [`eq_ignore_ascii_case`]: https://doc.rust-lang.org/std/ascii/trait.AsciiExt.html#tymethod.eq_ignore_ascii_case
381 pub fn eq_ignore_ascii_caserust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]eq_ignore_ascii_case().(&self, other: &Selfrust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]) -> bool {
382 (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().other) || self.eq_str_ignore_ascii_caserust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]eq_str_ignore_ascii_case().(&*rust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().other)
383 }
384
385 /// Like [`eq_ignore_ascii_case`], but takes an unhashed string as `other`.
386 ///
387 /// [`eq_ignore_ascii_case`]: https://doc.rust-lang.org/std/ascii/trait.AsciiExt.html#tymethod.eq_ignore_ascii_case
388 pub fn eq_str_ignore_ascii_caserust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`]eq_str_ignore_ascii_case().(&self, other: &str) -> bool {
389 (&*rust-analyzer cargo string_cache 0.9.0 atom/impl#[`Atom<Static>`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self).eq_ignore_ascii_caserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]eq_ignore_ascii_case().(other)
390 }
391 }
392
393 #[inline(always)]
394 fn inline_atom_slicerust-analyzer cargo string_cache 0.9.0 atom/inline_atom_slice().(x: &NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64#) -> &[u8] {
395 let x: *const NonZeroU64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/NonZeroU64# = x;
396 let mut data = x as *const u8;
397 // All except the lowest byte, which is first in little-endian, last in big-endian.
398 if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_endian = "little") {
399 data = unsafe { data.offsetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]offset().(1) };
400 }
401 let len = 7;
402 unsafe { slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/::from_raw_partsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/raw/from_raw_parts().(data, len) }
403 }
404
405 #[inline(always)]
406 fn inline_atom_slice_mutrust-analyzer cargo string_cache 0.9.0 atom/inline_atom_slice_mut().(x: &mut u64) -> &mut [u8] {
407 let x: *mut u64 = x;
408 let mut data = x as *mut u8;
409 // All except the lowest byte, which is first in little-endian, last in big-endian.
410 if cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(target_endian = "little") {
411 data = unsafe { data.offsetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]offset().(1) };
412 }
413 let len = 7;
414 unsafe { slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/::from_raw_parts_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/raw/from_raw_parts_mut().(data, len) }
415 }