Skip to content

Commit

Permalink
Unrolled build for rust-lang#118450
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#118450 - marcin-serwin:master, r=workingjubilee

Use OnceCell in cell module documentation

The spanning tree example in the std cell module implementation was created before `OnceCell` was added to Rust so it uses `RefCell`. However, in this case using `OnceCell` seems more appropriate and produces simpler code. As a bonus, this also means that all three cell types are presented in the examples of std cell module.
  • Loading branch information
rust-timer authored Dec 6, 2023
2 parents 84a554c + 13c16e3 commit efb7747
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,17 @@
//!
//! ```
//! # #![allow(dead_code)]
//! use std::cell::RefCell;
//! use std::cell::OnceCell;
//!
//! struct Graph {
//! edges: Vec<(i32, i32)>,
//! span_tree_cache: RefCell<Option<Vec<(i32, i32)>>>
//! span_tree_cache: OnceCell<Vec<(i32, i32)>>
//! }
//!
//! impl Graph {
//! fn minimum_spanning_tree(&self) -> Vec<(i32, i32)> {
//! self.span_tree_cache.borrow_mut()
//! .get_or_insert_with(|| self.calc_span_tree())
//! self.span_tree_cache
//! .get_or_init(|| self.calc_span_tree())
//! .clone()
//! }
//!
Expand Down

0 comments on commit efb7747

Please sign in to comment.