| Crates.io | fopencookie |
| lib.rs | fopencookie |
| version | 0.1.1 |
| created_at | 2024-05-10 11:59:18.549447+00 |
| updated_at | 2024-05-10 12:02:39.15116+00 |
| description | interface between std::io and libc::FILE |
| homepage | https://crates.io/fopencookie |
| repository | https://github.com/aatifsyed/fopencookie |
| max_upload_size | |
| id | 1235940 |
| size | 25,252 |
Convert an [io::Write]/[io::Read]/[io::Seek] to a [libc::FILE] stream
using the fopencookie syscall.
Great for passing rust traits across FFI.
let mut v = vec![];
let stream = fopencookie::IoCStream::writer(&mut v);
// Use the libc stream functions
assert_eq!(
unsafe {
libc::fprintf(stream.as_ptr(), c"hello, world!".as_ptr())
},
13 // all bytes written
);
// It's reflected in our rust type!
assert_eq!(v, b"hello, world!");
Trait objects are supported!
let mut reader: Box<dyn io::Read>;
let stream = fopencookie::IoCStream::reader(reader);
You can use the [Builder] for more flexibility.
let mut file: File;
let stream = fopencookie::Builder::new()
.read()
.write()
.seek()
.build(file);