Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 // Original work Copyright (c) 2014 The Rust Project Developers
2 // Modified work Copyright (c) 2016-2020 Nikita Pekin and the lazycell contributors
3 // See the README.md file at the top-level directory of this distribution.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![cfg_attr(not(test), no_std)]
12
13 #![deny(missing_docs)]
14 #![cfg_attr(feature = "nightly", feature(plugin))]
15 #![cfg_attr(feature = "clippy", plugin(clippy))]
16
17 //! This crate provides a `LazyCell` struct which acts as a lazily filled
18 //! `Cell`.
19 //!
20 //! With a `RefCell`, the inner contents cannot be borrowed for the lifetime of
21 //! the entire object, but only of the borrows returned. A `LazyCell` is a
22 //! variation on `RefCell` which allows borrows to be tied to the lifetime of
23 //! the outer object.
24 //!
25 //! # Example
26 //!
27 //! The following example shows a quick example of the basic functionality of
28 //! `LazyCell`.
29 //!
30 //! ```
31 //! use lazycell::LazyCell;
32 //!
33 //! let lazycell = LazyCell::new();
34 //!
35 //! assert_eq!(lazycell.borrow(), None);
36 //! assert!(!lazycell.filled());
37 //! lazycell.fill(1).ok();
38 //! assert!(lazycell.filled());
39 //! assert_eq!(lazycell.borrow(), Some(&1));
40 //! assert_eq!(lazycell.into_inner(), Some(1));
41 //! ```
42 //!
43 //! `AtomicLazyCell` is a variant that uses an atomic variable to manage
44 //! coordination in a thread-safe fashion. The limitation of an `AtomicLazyCell`
45 //! is that after it is initialized, it can't be modified.
46
47
48 #[cfg(not(test))]
49 #[macro_use]
50 extern crate core as std;
51 #[cfg(feature = "serde")]
52 extern crate serderust-analyzer cargo lazycell 1.3.0 serde/;
53
54 #[cfg(feature = "serde")]
55 mod serde_implrust-analyzer cargo lazycell 1.3.0 serde_impl/;
56
57 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/::UnsafeCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/UnsafeCell#;
58 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/;
59 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/::{AtomicUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicUsize#, Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#};
60
61 /// A lazily filled `Cell`, with mutable contents.
62 ///
63 /// A `LazyCell` is completely frozen once filled, **unless** you have `&mut`
64 /// access to it, in which case `LazyCell::borrow_mut` may be used to mutate the
65 /// contents.
66 #[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:)]
67 pub struct LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#<T> {
68 innerrust-analyzer cargo lazycell 1.3.0 LazyCell#inner.: UnsafeCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/UnsafeCell#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T>>,
69 }
70
71 impl<T> LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#<T> {
72 /// Creates a new, empty, `LazyCell`.
73 pub fn newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().() -> LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#<T> {
74 LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell# { innerrust-analyzer cargo lazycell 1.3.0 LazyCell#inner.: UnsafeCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/UnsafeCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]new().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) }
75 }
76
77 /// Put a value into this cell.
78 ///
79 /// This function will return `Err(value)` if the cell is already full.
80 pub fn fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(&self, value: T) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), T> {
81 let slot = unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo lazycell 1.3.0 LazyCell#inner..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]get().() };
82 if slot.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
83 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(value);
84 }
85 let slot = unsafe { &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo lazycell 1.3.0 LazyCell#inner..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]get().() };
86 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().slot = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value);
87
88 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
89 }
90
91 /// Put a value into this cell.
92 ///
93 /// Note that this function is infallible but requires `&mut self`. By
94 /// requiring `&mut self` we're guaranteed that no active borrows to this
95 /// cell can exist so we can always fill in the value. This may not always
96 /// be usable, however, as `&mut self` may not be possible to borrow.
97 ///
98 /// # Return value
99 ///
100 /// This function returns the previous value, if any.
101 pub fn replacerust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]replace().(&mut self, value: T) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T> {
102 memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::replacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/replace().(unsafe { &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo lazycell 1.3.0 LazyCell#inner..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]get().() }, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value))
103 }
104
105 /// Test whether this cell has been previously filled.
106 pub fn filledrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]filled().(&self) -> bool {
107 self.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()
108 }
109
110 /// Borrows the contents of this lazy cell for the duration of the cell
111 /// itself.
112 ///
113 /// This function will return `Some` if the cell has been previously
114 /// initialized, and `None` if it has not yet been initialized.
115 pub fn borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&T> {
116 unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo lazycell 1.3.0 LazyCell#inner..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]get().() }.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()
117 }
118
119 /// Borrows the contents of this lazy cell mutably for the duration of the cell
120 /// itself.
121 ///
122 /// This function will return `Some` if the cell has been previously
123 /// initialized, and `None` if it has not yet been initialized.
124 pub fn borrow_mutrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow_mut().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&mut T> {
125 unsafe { &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo lazycell 1.3.0 LazyCell#inner..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]get().() }.as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().()
126 }
127
128 /// Borrows the contents of this lazy cell for the duration of the cell
129 /// itself.
130 ///
131 /// If the cell has not yet been filled, the cell is first filled using the
132 /// function provided.
133 ///
134 /// # Panics
135 ///
136 /// Panics if the cell becomes filled as a side effect of `f`.
137 pub fn borrow_withrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow_with().<F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> T>(&self, f: F) -> &T {
138 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = self.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().() {
139 return value;
140 }
141 let value = f();
142 if self.fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(value).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().() {
143 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("borrow_with: cell was filled by closure")
144 }
145 self.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
146 }
147
148 /// Borrows the contents of this `LazyCell` mutably for the duration of the
149 /// cell itself.
150 ///
151 /// If the cell has not yet been filled, the cell is first filled using the
152 /// function provided.
153 ///
154 /// # Panics
155 ///
156 /// Panics if the cell becomes filled as a side effect of `f`.
157 pub fn borrow_mut_withrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow_mut_with().<F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> T>(&mut self, f: F) -> &mut T {
158 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.filledrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]filled().() {
159 let value = f();
160 if self.fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(value).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().() {
161 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("borrow_mut_with: cell was filled by closure")
162 }
163 }
164
165 self.borrow_mutrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow_mut().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
166 }
167
168 /// Same as `borrow_with`, but allows the initializing function to fail.
169 ///
170 /// # Panics
171 ///
172 /// Panics if the cell becomes filled as a side effect of `f`.
173 pub fn try_borrow_withrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]try_borrow_with().<E, F>(&self, f: F) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&T, E>
174 where F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>
175 {
176 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = self.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().() {
177 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(value);
178 }
179 let value = f()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
180 if self.fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(value).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().() {
181 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("try_borrow_with: cell was filled by closure")
182 }
183 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().())
184 }
185
186 /// Same as `borrow_mut_with`, but allows the initializing function to fail.
187 ///
188 /// # Panics
189 ///
190 /// Panics if the cell becomes filled as a side effect of `f`.
191 pub fn try_borrow_mut_withrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]try_borrow_mut_with().<E, F>(&mut self, f: F) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&mut T, E>
192 where F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>
193 {
194 if self.filledrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]filled().() {
195 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.borrow_mutrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow_mut().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().());
196 }
197 let value = f()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
198 if self.fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(value).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().() {
199 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("try_borrow_mut_with: cell was filled by closure")
200 }
201 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.borrow_mutrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow_mut().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().())
202 }
203
204 /// Consumes this `LazyCell`, returning the underlying value.
205 pub fn into_innerrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]into_inner().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T> {
206 // Rust 1.25 changed UnsafeCell::into_inner() from unsafe to safe
207 // function. This unsafe can be removed when supporting Rust older than
208 // 1.25 is not needed.
209 #[allow(unused_unsafe)]
210 unsafe { self.innerrust-analyzer cargo lazycell 1.3.0 LazyCell#inner..into_innerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]into_inner().() }
211 }
212 }
213
214 impl<T: Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy#> LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#<T> {
215 /// Returns a copy of the contents of the lazy cell.
216 ///
217 /// This function will return `Some` if the cell has been previously initialized,
218 /// and `None` if it has not yet been initialized.
219 pub fn getrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]get().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T> {
220 unsafe { *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo lazycell 1.3.0 LazyCell#inner..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]get().() }
221 }
222 }
223
224 impl<T> Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#<T> {
225 fn defaultrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`][Default]default().() -> Selfrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`][Default] {
226 Selfrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`][Default]::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().()
227 }
228 }
229
230 impl <T: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#<T> {
231 /// Create a clone of this `LazyCell`
232 ///
233 /// If self has not been initialized, returns an uninitialized `LazyCell`
234 /// otherwise returns a `LazyCell` already initialized with a clone of the
235 /// contents of self.
236 fn clonerust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`][Clone]clone().(&self) -> LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#<T> {
237 LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell# { innerrust-analyzer cargo lazycell 1.3.0 LazyCell#inner.: UnsafeCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/UnsafeCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]new().(self.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#::clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().) ) }
238 }
239 }
240
241 // Tracks the AtomicLazyCell inner state
242 const NONErust-analyzer cargo lazycell 1.3.0 NONE.: usize = 0;
243 const LOCKrust-analyzer cargo lazycell 1.3.0 LOCK.: usize = 1;
244 const SOMErust-analyzer cargo lazycell 1.3.0 SOME.: usize = 2;
245
246 /// A lazily filled and thread-safe `Cell`, with frozen contents.
247 #[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:)]
248 pub struct AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#<T> {
249 innerrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#inner.: UnsafeCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/UnsafeCell#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T>>,
250 staterust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#state.: AtomicUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicUsize#,
251 }
252
253 impl<T> AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#<T> {
254 /// An empty `AtomicLazyCell`.
255 pub const NONErust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]NONE.: Selfrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`] = Selfrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`] {
256 innerrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#inner.: UnsafeCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/UnsafeCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]new().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
257 staterust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#state.: AtomicUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicUsize#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]new().(NONErust-analyzer cargo lazycell 1.3.0 NONE.),
258 };
259
260 /// Creates a new, empty, `AtomicLazyCell`.
261 pub fn newrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]new().() -> AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#<T> {
262 Selfrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]::NONErust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]NONE.
263 }
264
265 /// Put a value into this cell.
266 ///
267 /// This function will return `Err(value)` if the cell is already full.
268 pub fn fillrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]fill().(&self, t: T) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), T> {
269 if NONErust-analyzer cargo lazycell 1.3.0 NONE. 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().self.staterust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#state..compare_and_swaprust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]compare_and_swap().(NONErust-analyzer cargo lazycell 1.3.0 NONE., LOCKrust-analyzer cargo lazycell 1.3.0 LOCK., Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#) {
270 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(t);
271 }
272
273 unsafe { *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#inner..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]get().() = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(t) };
274
275 if LOCKrust-analyzer cargo lazycell 1.3.0 LOCK. 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().self.staterust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#state..compare_and_swaprust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]compare_and_swap().(LOCKrust-analyzer cargo lazycell 1.3.0 LOCK., SOMErust-analyzer cargo lazycell 1.3.0 SOME., Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::Releaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Release#) {
276 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("unable to release lock");
277 }
278
279 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
280 }
281
282 /// Put a value into this cell.
283 ///
284 /// Note that this function is infallible but requires `&mut self`. By
285 /// requiring `&mut self` we're guaranteed that no active borrows to this
286 /// cell can exist so we can always fill in the value. This may not always
287 /// be usable, however, as `&mut self` may not be possible to borrow.
288 ///
289 /// # Return value
290 ///
291 /// This function returns the previous value, if any.
292 pub fn replacerust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]replace().(&mut self, value: T) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T> {
293 match memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::replacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/replace().(self.staterust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#state..get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]get_mut().(), SOMErust-analyzer cargo lazycell 1.3.0 SOME.) {
294 NONErust-analyzer cargo lazycell 1.3.0 NONE. | SOMErust-analyzer cargo lazycell 1.3.0 SOME. => {}
295 _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("cell in inconsistent state"),
296 }
297 memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::replacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/replace().(unsafe { &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#inner..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]get().() }, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value))
298 }
299
300 /// Test whether this cell has been previously filled.
301 pub fn filledrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]filled().(&self) -> bool {
302 self.staterust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#state..loadrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]load().(Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#) 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().SOMErust-analyzer cargo lazycell 1.3.0 SOME.
303 }
304
305 /// Borrows the contents of this lazy cell for the duration of the cell
306 /// itself.
307 ///
308 /// This function will return `Some` if the cell has been previously
309 /// initialized, and `None` if it has not yet been initialized.
310 pub fn borrowrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]borrow().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&T> {
311 match self.staterust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#state..loadrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]load().(Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#) {
312 SOMErust-analyzer cargo lazycell 1.3.0 SOME. => unsafe { &*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#inner..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]get().() }.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().(),
313 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
314 }
315 }
316
317 /// Consumes this `LazyCell`, returning the underlying value.
318 pub fn into_innerrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]into_inner().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T> {
319 // Rust 1.25 changed UnsafeCell::into_inner() from unsafe to safe
320 // function. This unsafe can be removed when supporting Rust older than
321 // 1.25 is not needed.
322 #[allow(unused_unsafe)]
323 unsafe { self.innerrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#inner..into_innerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]into_inner().() }
324 }
325 }
326
327 impl<T: Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy#> AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#<T> {
328 /// Returns a copy of the contents of the lazy cell.
329 ///
330 /// This function will return `Some` if the cell has been previously initialized,
331 /// and `None` if it has not yet been initialized.
332 pub fn getrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]get().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T> {
333 match self.staterust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#state..loadrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]load().(Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#::Acquirerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/Ordering#Acquire#) {
334 SOMErust-analyzer cargo lazycell 1.3.0 SOME. => unsafe { *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().self.innerrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#inner..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]get().() },
335 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
336 }
337 }
338 }
339
340 impl<T> Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#<T> {
341 fn defaultrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`][Default]default().() -> Selfrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`][Default] {
342 Selfrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`][Default]::newrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]new().()
343 }
344 }
345
346 impl<T: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#<T> {
347 /// Create a clone of this `AtomicLazyCell`
348 ///
349 /// If self has not been initialized, returns an uninitialized `AtomicLazyCell`
350 /// otherwise returns an `AtomicLazyCell` already initialized with a clone of the
351 /// contents of self.
352 fn clonerust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`][Clone]clone().(&self) -> AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#<T> {
353 self.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]borrow().().map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(
354 Selfrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`][Clone]::NONErust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]NONE.,
355 |v| AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell# {
356 innerrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#inner.: UnsafeCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/UnsafeCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]new().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().())),
357 staterust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#state.: AtomicUsizerust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/AtomicUsize#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core sync/atomic/impl#[AtomicUsize]new().(SOMErust-analyzer cargo lazycell 1.3.0 SOME.),
358 }
359 )
360 }
361 }
362
363 unsafe impl<T: Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# for AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#<T> {}
364
365 unsafe impl<T: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# for AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#<T> {}
366
367 #[cfg(test)]
368 mod testsrust-analyzer cargo lazycell 1.3.0 tests/ {
369 use superrust-analyzer cargo lazycell 1.3.0 crate/::{AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#, LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#};
370
371 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
372 fn test_borrow_from_emptyrust-analyzer cargo lazycell 1.3.0 tests/test_borrow_from_empty().() {
373 let lazycell: LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#<usize> = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
374
375 let value = lazycell.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().();
376 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(value, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
377
378 let value = lazycell.getrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]get().();
379 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(value, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
380 }
381
382 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
383 fn test_fill_and_borrowrust-analyzer cargo lazycell 1.3.0 tests/test_fill_and_borrow().() {
384 let lazycell = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
385
386 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().lazycell.filledrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]filled().());
387 lazycell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
388 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(lazycell.filledrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]filled().());
389
390 let value = lazycell.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().();
391 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(value, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&1));
392
393 let value = lazycell.getrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]get().();
394 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(value, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1));
395 }
396
397 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
398 fn test_borrow_mutrust-analyzer cargo lazycell 1.3.0 tests/test_borrow_mut().() {
399 let mut lazycell = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
400 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(lazycell.borrow_mutrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow_mut().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
401
402 lazycell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
403 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(lazycell.borrow_mutrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow_mut().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&mut 1));
404
405 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().lazycell.borrow_mutrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow_mut().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() = 2;
406 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(lazycell.borrow_mutrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow_mut().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&mut 2));
407
408 // official way to reset the cell
409 lazycell = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
410 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(lazycell.borrow_mutrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow_mut().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
411 }
412
413 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
414 fn test_already_filled_errorrust-analyzer cargo lazycell 1.3.0 tests/test_already_filled_error().() {
415 let lazycell = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
416
417 lazycell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
418 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(lazycell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(1), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(1));
419 }
420
421 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
422 fn test_borrow_withrust-analyzer cargo lazycell 1.3.0 tests/test_borrow_with().() {
423 let lazycell = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
424
425 let value = lazycell.borrow_withrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow_with().(|| 1);
426 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&1, value);
427 }
428
429 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
430 fn test_borrow_with_already_filledrust-analyzer cargo lazycell 1.3.0 tests/test_borrow_with_already_filled().() {
431 let lazycell = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
432 lazycell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
433
434 let value = lazycell.borrow_withrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow_with().(|| 1);
435 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&1, value);
436 }
437
438 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
439 fn test_borrow_with_not_called_when_filledrust-analyzer cargo lazycell 1.3.0 tests/test_borrow_with_not_called_when_filled().() {
440 let lazycell = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
441
442 lazycell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
443
444 let value = lazycell.borrow_withrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow_with().(|| 2);
445 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&1, value);
446 }
447
448 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
449 #[should_panic]
450 fn test_borrow_with_sound_with_reentrancyrust-analyzer cargo lazycell 1.3.0 tests/test_borrow_with_sound_with_reentrancy().() {
451 // Kudos to dbaupp for discovering this issue
452 // https://www.reddit.com/r/rust/comments/5vs9rt/lazycell_a_rust_library_providing_a_lazilyfilled/de527xm/
453 let lazycell: LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<i32>> = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
454
455 let mut reference: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&i32> = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
456
457 lazycell.borrow_withrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow_with().(|| {
458 let _ = lazycell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(1));
459 reference = lazycell.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|r| &*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().r);
460 Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(2)
461 });
462 }
463
464 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
465 fn test_borrow_mut_withrust-analyzer cargo lazycell 1.3.0 tests/test_borrow_mut_with().() {
466 let mut lazycell = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
467
468 {
469 let value = lazycell.borrow_mut_withrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow_mut_with().(|| 1);
470 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&mut 1, value);
471 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().value = 2;
472 }
473 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&2, lazycell.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().());
474 }
475
476 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
477 fn test_borrow_mut_with_already_filledrust-analyzer cargo lazycell 1.3.0 tests/test_borrow_mut_with_already_filled().() {
478 let mut lazycell = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
479 lazycell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
480
481 let value = lazycell.borrow_mut_withrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow_mut_with().(|| 1);
482 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&1, value);
483 }
484
485 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
486 fn test_borrow_mut_with_not_called_when_filledrust-analyzer cargo lazycell 1.3.0 tests/test_borrow_mut_with_not_called_when_filled().() {
487 let mut lazycell = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
488
489 lazycell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
490
491 let value = lazycell.borrow_mut_withrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow_mut_with().(|| 2);
492 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&1, value);
493 }
494
495 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
496 fn test_try_borrow_with_okrust-analyzer cargo lazycell 1.3.0 tests/test_try_borrow_with_ok().() {
497 let lazycell = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
498 let result = lazycell.try_borrow_withrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]try_borrow_with().::<(), _>(|| Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(1));
499 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(&1));
500 }
501
502 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
503 fn test_try_borrow_with_errrust-analyzer cargo lazycell 1.3.0 tests/test_try_borrow_with_err().() {
504 let lazycell = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::<()>::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
505 let result = lazycell.try_borrow_withrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]try_borrow_with().(|| Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(1));
506 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(1));
507 }
508
509 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
510 fn test_try_borrow_with_already_filledrust-analyzer cargo lazycell 1.3.0 tests/test_try_borrow_with_already_filled().() {
511 let lazycell = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
512 lazycell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
513 let result = lazycell.try_borrow_withrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]try_borrow_with().::<(), _>(|| unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!());
514 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(&1));
515 }
516
517 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
518 #[should_panic]
519 fn test_try_borrow_with_sound_with_reentrancyrust-analyzer cargo lazycell 1.3.0 tests/test_try_borrow_with_sound_with_reentrancy().() {
520 let lazycell: LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<i32>> = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
521
522 let mut reference: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&i32> = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
523
524 let _ = lazycell.try_borrow_withrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]try_borrow_with().::<(), _>(|| {
525 let _ = lazycell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(1));
526 reference = lazycell.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|r| &*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().r);
527 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(2))
528 });
529 }
530
531 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
532 fn test_try_borrow_mut_with_okrust-analyzer cargo lazycell 1.3.0 tests/test_try_borrow_mut_with_ok().() {
533 let mut lazycell = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
534 {
535 let result = lazycell.try_borrow_mut_withrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]try_borrow_mut_with().::<(), _>(|| Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(1));
536 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(&mut 1));
537 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().result.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() = 2;
538 }
539 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&mut 2, lazycell.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().());
540 }
541
542 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
543 fn test_try_borrow_mut_with_errrust-analyzer cargo lazycell 1.3.0 tests/test_try_borrow_mut_with_err().() {
544 let mut lazycell = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::<()>::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
545 let result = lazycell.try_borrow_mut_withrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]try_borrow_mut_with().(|| Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(1));
546 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(1));
547 }
548
549 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
550 fn test_try_borrow_mut_with_already_filledrust-analyzer cargo lazycell 1.3.0 tests/test_try_borrow_mut_with_already_filled().() {
551 let mut lazycell = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
552 lazycell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
553 let result = lazycell.try_borrow_mut_withrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]try_borrow_mut_with().::<(), _>(|| unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!());
554 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(&mut 1));
555 }
556
557 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
558 fn test_into_innerrust-analyzer cargo lazycell 1.3.0 tests/test_into_inner().() {
559 let lazycell = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
560
561 lazycell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
562 let value = lazycell.into_innerrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]into_inner().();
563 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(value, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1));
564 }
565
566 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
567 fn test_atomic_borrow_from_emptyrust-analyzer cargo lazycell 1.3.0 tests/test_atomic_borrow_from_empty().() {
568 let lazycell: AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#<usize> = AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]new().();
569
570 let value = lazycell.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]borrow().();
571 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(value, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
572
573 let value = lazycell.getrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]get().();
574 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(value, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
575 }
576
577 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
578 fn test_atomic_fill_and_borrowrust-analyzer cargo lazycell 1.3.0 tests/test_atomic_fill_and_borrow().() {
579 let lazycell = AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]new().();
580
581 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().lazycell.filledrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]filled().());
582 lazycell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]fill().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
583 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(lazycell.filledrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]filled().());
584
585 let value = lazycell.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]borrow().();
586 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(value, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&1));
587
588 let value = lazycell.getrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]get().();
589 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(value, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1));
590 }
591
592 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
593 fn test_atomic_already_filled_panicrust-analyzer cargo lazycell 1.3.0 tests/test_atomic_already_filled_panic().() {
594 let lazycell = AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]new().();
595
596 lazycell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]fill().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
597 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(1, lazycell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]fill().(1).unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().());
598 }
599
600 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
601 fn test_atomic_into_innerrust-analyzer cargo lazycell 1.3.0 tests/test_atomic_into_inner().() {
602 let lazycell = AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]new().();
603
604 lazycell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]fill().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
605 let value = lazycell.into_innerrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]into_inner().();
606 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(value, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1));
607 }
608
609 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
610 fn normal_replacerust-analyzer cargo lazycell 1.3.0 tests/normal_replace().() {
611 let mut cell = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
612 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(1), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
613 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cell.replacerust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]replace().(2), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1));
614 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cell.replacerust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]replace().(3), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2));
615 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cell.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&3));
616
617 let mut cell = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
618 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cell.replacerust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]replace().(2), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
619 }
620
621 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
622 fn atomic_replacerust-analyzer cargo lazycell 1.3.0 tests/atomic_replace().() {
623 let mut cell = AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]new().();
624 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]fill().(1), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
625 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cell.replacerust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]replace().(2), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1));
626 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cell.replacerust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]replace().(3), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2));
627 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cell.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]borrow().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&3));
628 }
629
630 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
631 fn clonerust-analyzer cargo lazycell 1.3.0 tests/clone().() {
632 let mut cell = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]new().();
633 let clone1 = cell.clonerust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`][Clone]clone().();
634 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clone1.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
635 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(1), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
636 let mut clone2 = cell.clonerust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`][Clone]clone().();
637 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clone1.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
638 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clone2.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&1));
639 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cell.replacerust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]replace().(2), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1));
640 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clone1.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
641 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clone2.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&1));
642 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clone1.fillrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]fill().(3), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
643 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clone2.replacerust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]replace().(4), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1));
644 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clone1.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&3));
645 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clone2.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&4));
646 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cell.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`]borrow().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&2));
647 }
648
649 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
650 fn clone_atomicrust-analyzer cargo lazycell 1.3.0 tests/clone_atomic().() {
651 let mut cell = AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#::newrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]new().();
652 let clone1 = cell.clonerust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`][Clone]clone().();
653 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clone1.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]borrow().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
654 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cell.fillrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]fill().(1), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
655 let mut clone2 = cell.clonerust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`][Clone]clone().();
656 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clone1.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]borrow().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
657 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clone2.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]borrow().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&1));
658 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cell.replacerust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]replace().(2), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1));
659 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clone1.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]borrow().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
660 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clone2.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]borrow().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&1));
661 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clone1.fillrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]fill().(3), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()));
662 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clone2.replacerust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]replace().(4), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1));
663 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clone1.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]borrow().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&3));
664 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(clone2.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]borrow().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&4));
665 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cell.borrowrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`]borrow().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&2));
666 }
667
668 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
669 fn defaultrust-analyzer cargo lazycell 1.3.0 tests/default().() {
670 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
671 struct Defaultablerust-analyzer cargo lazycell 1.3.0 tests/Defaultable#;
672 struct NonDefaultablerust-analyzer cargo lazycell 1.3.0 tests/NonDefaultable#;
673
674 let _: LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#<Defaultablerust-analyzer cargo lazycell 1.3.0 tests/Defaultable#> = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::defaultrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`][Default]default().();
675 let _: LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#<NonDefaultablerust-analyzer cargo lazycell 1.3.0 tests/NonDefaultable#> = LazyCellrust-analyzer cargo lazycell 1.3.0 LazyCell#::defaultrust-analyzer cargo lazycell 1.3.0 impl#[`LazyCell<T>`][Default]default().();
676
677 let _: AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#<Defaultablerust-analyzer cargo lazycell 1.3.0 tests/Defaultable#> = AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#::defaultrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`][Default]default().();
678 let _: AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#<NonDefaultablerust-analyzer cargo lazycell 1.3.0 tests/NonDefaultable#> = AtomicLazyCellrust-analyzer cargo lazycell 1.3.0 AtomicLazyCell#::defaultrust-analyzer cargo lazycell 1.3.0 impl#[`AtomicLazyCell<T>`][Default]default().();
679 }
680 }