Crates.io | rc-writer |
lib.rs | rc-writer |
version | 1.1.10 |
source | src |
created_at | 2018-10-24 12:04:49.11718 |
updated_at | 2022-03-18 12:36:37.033698 |
description | A tiny implement for writing data to a reference counted instance. |
homepage | https://magiclen.org/rc-writer |
repository | https://github.com/magiclen/rc-writer |
max_upload_size | |
id | 92370 |
size | 6,392 |
A tiny implement for writing data to a reference counted instance.
use rc_writer::RcWriter;
use std::rc::Rc;
use std::cell::RefCell;
use std::io::Write;
let data = RefCell::new(Vec::new());
let data_rc = Rc::new(data);
let mut writer = RcWriter::new(data_rc.clone());
writer.write(b"Hello world!").unwrap();
writer.flush().unwrap();
assert_eq!(b"Hello world!".to_vec(), *data_rc.borrow());
use rc_writer::RcOptionWriter;
use std::rc::Rc;
use std::cell::RefCell;
use std::io::Write;
let data = RefCell::new(Some(Vec::new()));
let data_rc = Rc::new(data);
let mut writer = RcOptionWriter::new(data_rc.clone());
writer.write(b"Hello world!").unwrap();
writer.flush().unwrap();
let data = data_rc.borrow_mut().take().unwrap(); // remove out the vec from rc
assert_eq!(b"Hello world!".to_vec(), data);
https://crates.io/crates/rc-writer