anybytes 0.20.2

A small library abstracting over bytes owning types in an extensible way.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use anybytes::{Bytes, PyAnyBytes};
use pyo3::prelude::*;

fn main() -> PyResult<()> {
    Python::with_gil(|py| {
        let bytes = Bytes::from(vec![1u8, 2, 3, 4]);
        let wrapped = Py::new(py, PyAnyBytes::new(bytes))?;

        let builtins = PyModule::import(py, "builtins")?;
        let memoryview = builtins.getattr("memoryview")?.call1((wrapped.bind(py),))?;
        let length: usize = memoryview.getattr("__len__")?.call0()?.extract()?;
        assert_eq!(length, 4);
        Ok(())
    })
}