#rc #refcell #write #option #refmut

rc-writer

A tiny implement for writing data to a reference counted instance

11 stable releases

1.1.9 Apr 22, 2021
1.1.8 Jul 29, 2020
1.1.7 Jun 27, 2020
1.1.6 Sep 17, 2019
1.1.1 Nov 14, 2018

#295 in Data structures

Download history 30/week @ 2021-08-15 35/week @ 2021-08-22 33/week @ 2021-08-29 18/week @ 2021-09-05 17/week @ 2021-09-12 35/week @ 2021-09-19 16/week @ 2021-09-26 39/week @ 2021-10-03 32/week @ 2021-10-10 10/week @ 2021-10-17 21/week @ 2021-10-24 29/week @ 2021-10-31 21/week @ 2021-11-07 9/week @ 2021-11-14 12/week @ 2021-11-21 43/week @ 2021-11-28

88 downloads per month

MIT license

5KB
58 lines

Rc Writer

CI

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

Examples

RcWriter

extern crate rc_writer;

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

extern crate rc_writer;

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

No runtime deps

D3`