#rc #refcell #write #options #refmut

rc-writer

A tiny implement for writing data to a reference counted instance

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

#467 in Data structures

Download history 13/week @ 2024-01-01 39/week @ 2024-01-08 18/week @ 2024-01-15 9/week @ 2024-01-22 13/week @ 2024-01-29 10/week @ 2024-02-05 136/week @ 2024-02-12 36/week @ 2024-02-19 113/week @ 2024-02-26 111/week @ 2024-03-04 47/week @ 2024-03-11 48/week @ 2024-03-18 69/week @ 2024-03-25 95/week @ 2024-04-01 32/week @ 2024-04-08 35/week @ 2024-04-15

240 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