1
0
mirror of https://github.com/jht5945/rust_util.git synced 2025-12-27 15:40:03 +08:00

do not use RefCell

This commit is contained in:
2019-08-03 18:00:49 +08:00
parent a67337bb5d
commit db35e8e55b

View File

@@ -1,7 +1,7 @@
extern crate term; extern crate term;
use std::{ use std::{
cell::RefCell, //cell::RefCell,
env, env,
fs, fs,
io::{self, Write, Error, ErrorKind}, io::{self, Write, Error, ErrorKind},
@@ -241,11 +241,11 @@ pub fn extract_package_and_wait(dir: &str, file_name: &str) -> io::Result<()> {
pub fn copy_io<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W, total: i64) -> io::Result<u64> pub fn copy_io<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W, total: i64) -> io::Result<u64>
where R: io::Read, W: io::Write { where R: io::Read, W: io::Write {
let written_cell = RefCell::new(0u64); //let written_cell = RefCell::new(0u64);
let start = SystemTime::now(); let start = SystemTime::now();
let written = copy_io_callback(reader, writer, total, &|total, _written, len| { let written = copy_io_callback(reader, writer, total, &|total, written, _len| {
written_cell.replace_with(|&mut w| w + len as u64); //written_cell.replace_with(|&mut w| w + len as u64);
let written = *written_cell.borrow(); //let written = *written_cell.borrow();
let cost = SystemTime::now().duration_since(start.clone()).unwrap().as_secs(); let cost = SystemTime::now().duration_since(start.clone()).unwrap().as_secs();
let mut download_speed = "-".to_string(); let mut download_speed = "-".to_string();
if cost > 0 { if cost > 0 {