Skip to content

Commit e651d41

Browse files
Replace LazyCell with OnceCell
1 parent 63cd135 commit e651d41

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

text/paste.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use clap::Parser;
1818
use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
1919
use plib::PROJECT_NAME;
20-
use std::cell::{LazyCell, RefCell};
20+
use std::cell::{OnceCell, RefCell};
2121
use std::error::Error;
2222
use std::fs::File;
2323
use std::io::{self, BufRead, BufReader, Stdin, Write};
@@ -237,7 +237,7 @@ fn parse_delims_argument(delims: Option<String>) -> Result<Box<[Box<[u8]>]>, Str
237237
}
238238

239239
fn open_inputs(files: Vec<String>) -> Result<PasteInfo, Box<dyn Error>> {
240-
let stdin_lazy_cell = LazyCell::new(|| Rc::new(RefCell::new(io::stdin())));
240+
let stdin_once_cell = OnceCell::<Rc<RefCell<Stdin>>>::new();
241241

242242
let mut paste_file_vec = Vec::<PasteFile>::with_capacity(files.len());
243243

@@ -249,7 +249,9 @@ fn open_inputs(files: Vec<String>) -> Result<PasteInfo, Box<dyn Error>> {
249249
match file.as_str() {
250250
"-" => {
251251
paste_file_vec.push(PasteFile::new(Source::StandardInput(
252-
stdin_lazy_cell.clone(),
252+
stdin_once_cell
253+
.get_or_init(|| Rc::new(RefCell::new(io::stdin())))
254+
.clone(),
253255
)));
254256
}
255257
"" => {

0 commit comments

Comments
 (0)