rc-writer

Crates.iorc-writer
lib.rsrc-writer
version1.1.10
sourcesrc
created_at2018-10-24 12:04:49.11718
updated_at2022-03-18 12:36:37.033698
descriptionA tiny implement for writing data to a reference counted instance.
homepagehttps://magiclen.org/rc-writer
repositoryhttps://github.com/magiclen/rc-writer
max_upload_size
id92370
size6,392
Magic Len (Ron Li) (magiclen)

documentation

README

Rc Writer

CI

A tiny implement for writing data to a reference counted instance.

Examples

RcWriter

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());

RcOptionWriter

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);

Crates.io

https://crates.io/crates/rc-writer

Documentation

https://docs.rs/rc-writer

License

MIT

Commit count: 16

cargo fmt