Skip to content

Commit

Permalink
Merge #212
Browse files Browse the repository at this point in the history
212: Fixed `LateInit` recipe stack overflow r=matklad a=jack-cooper

The given `LateInit` recipe works up until the print statement, which causes a stack overflow as the derived `Debug` implementation tries to write out:
```rs
LateInit { cell: OnceCell(A { b: LateInit { cell: OnceCell(B { a: LateInit // repeats endlessly from here
```
To fix this, I've added in a rudimentary `Debug` impl.

Co-authored-by: jack-cooper <cooper.jackwilliam@gmail.com>
  • Loading branch information
bors[bot] and jack-cooper committed Dec 24, 2022
2 parents ba8b9fe + e94003a commit 0d0dae1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/lib.rs
Expand Up @@ -208,7 +208,6 @@
//! ```
//! use once_cell::sync::OnceCell;
//!
//! #[derive(Debug)]
//! pub struct LateInit<T> { cell: OnceCell<T> }
//!
//! impl<T> LateInit<T> {
Expand All @@ -228,22 +227,24 @@
//! }
//! }
//!
//! #[derive(Default, Debug)]
//! #[derive(Default)]
//! struct A<'a> {
//! b: LateInit<&'a B<'a>>,
//! }
//!
//! #[derive(Default, Debug)]
//! #[derive(Default)]
//! struct B<'a> {
//! a: LateInit<&'a A<'a>>
//! }
//!
//!
//! fn build_cycle() {
//! let a = A::default();
//! let b = B::default();
//! a.b.init(&b);
//! b.a.init(&a);
//! println!("{:?}", a.b.a.b.a);
//!
//! let _a = &a.b.a.b.a;
//! }
//! ```
//!
Expand Down Expand Up @@ -314,9 +315,9 @@
//! **Does this crate support async?**
//!
//! No, but you can use [`async_once_cell`](https://crates.io/crates/async_once_cell) instead.
//!
//!
//! **Can I bring my own mutex?**
//!
//!
//! There is [generic_once_cell](https://crates.io/crates/generic_once_cell) to allow just that.
//!
//! # Related crates
Expand Down

0 comments on commit 0d0dae1

Please sign in to comment.