read_with 0.1.0

Create a Read from a function
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented1 out of 3 items with examples
  • Size
  • Source code size: 5.95 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.46 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • njaard/read_with
    0 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • njaard

GitHub license Crates.io

This implements the Read trait, calling a function to generate the data.

See the API documentation.

Import Crate

read_with="0.1"

Example

let mut output = vec!();
let many_strings = ["one", "two", "three"];
let mut pos = 0;

std::io::copy(
    &mut ReadWith::new(
        ||
        {
            if pos == many_strings.len() { return None; }
            let o = many_strings[pos];
            pos+=1;
            Some(o)
        }
    ),
    &mut output,
).unwrap();
assert_eq!("onetwothree", str::from_utf8(&output).unwrap());