#rc #refcell #write #option #refmut

rc-writer

A tiny implement for writing data to a reference counted instance

12 stable releases

Uses new Rust 2021

1.1.10 Mar 18, 2022
1.1.9 Apr 22, 2021
1.1.8 Jul 29, 2020
1.1.6 Sep 17, 2019
1.1.1 Nov 14, 2018

#320 in Data structures

Download history 71/week @ 2022-08-17 39/week @ 2022-08-24 53/week @ 2022-08-31 54/week @ 2022-09-07 72/week @ 2022-09-14 78/week @ 2022-09-21 136/week @ 2022-09-28 105/week @ 2022-10-05 67/week @ 2022-10-12 41/week @ 2022-10-19 92/week @ 2022-10-26 90/week @ 2022-11-02 88/week @ 2022-11-09 83/week @ 2022-11-16 90/week @ 2022-11-23 48/week @ 2022-11-30

326 downloads per month

MIT license

5KB
58 lines

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

No runtime deps