Skip to content

Commit 3f750e1

Browse files
committed
Fixed LateInit example stack overflow
1 parent ba8b9fe commit 3f750e1

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/lib.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@
206206
//!
207207
//!
208208
//! ```
209+
//! use std::fmt;
210+
//!
209211
//! use once_cell::sync::OnceCell;
210212
//!
211213
//! #[derive(Debug)]
@@ -228,16 +230,28 @@
228230
//! }
229231
//! }
230232
//!
231-
//! #[derive(Default, Debug)]
233+
//! #[derive(Default)]
232234
//! struct A<'a> {
233235
//! b: LateInit<&'a B<'a>>,
234236
//! }
235237
//!
236-
//! #[derive(Default, Debug)]
238+
//! #[derive(Default)]
237239
//! struct B<'a> {
238240
//! a: LateInit<&'a A<'a>>
239241
//! }
240242
//!
243+
//! impl fmt::Debug for A<'_> {
244+
//! fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
245+
//! write!(f, "A")
246+
//! }
247+
//! }
248+
//!
249+
//! impl fmt::Debug for B<'_> {
250+
//! fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
251+
//! write!(f, "B")
252+
//! }
253+
//! }
254+
//!
241255
//! fn build_cycle() {
242256
//! let a = A::default();
243257
//! let b = B::default();
@@ -314,9 +328,9 @@
314328
//! **Does this crate support async?**
315329
//!
316330
//! No, but you can use [`async_once_cell`](https://crates.io/crates/async_once_cell) instead.
317-
//!
331+
//!
318332
//! **Can I bring my own mutex?**
319-
//!
333+
//!
320334
//! There is [generic_once_cell](https://crates.io/crates/generic_once_cell) to allow just that.
321335
//!
322336
//! # Related crates

0 commit comments

Comments
 (0)