12 stable releases

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

#686 in Data structures

Download history 53/week @ 2024-06-10 25/week @ 2024-06-17 17/week @ 2024-06-24 54/week @ 2024-07-01 94/week @ 2024-07-08 65/week @ 2024-07-15 54/week @ 2024-07-22 131/week @ 2024-07-29 33/week @ 2024-08-05 23/week @ 2024-08-12 43/week @ 2024-08-19 38/week @ 2024-08-26 41/week @ 2024-09-02 15/week @ 2024-09-09 20/week @ 2024-09-16 185/week @ 2024-09-23

271 downloads per month

MIT license

6KB
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