#image #canvas #vec #buffer #casting


An allocated buffer suitable for image data

7 releases

✓ Uses Rust 2018 edition

0.0.6 Jan 11, 2020
0.0.5 Jan 10, 2020
0.0.4 Jun 18, 2019
0.0.2 May 12, 2019
0.0.1-a Mar 31, 2019

#70 in Images

35 downloads per month

MIT license


Canvas docs.rs: image-canvas Build Status

An allocated buffer suitable for image data. Compared to a Vec of all samples, it restricts the possible data types but on the other hand focusses on a more efficient interface to casting the data or rearranging the contents.


After some discussion it was concluded that there is likely no safe way to reinterpret the allocation of a Vec<T> for a different Vec<U>, except in a very restricted set of cases. This includes grouping samples in logic pixel structs, even if those are annotated #[repr(C)] or alike. This is hardly the fault of Vec<_>, as images and the necessary transmutations of the representative binary data are far from general but Vec must be.


This library is not yet ready for use, and mostly a reservation in crates.io for future use within the image-rs organization managing the image crate.

It is also not intended to provide nd-algebra or other matrix style operations. This firstly keeps the implementation complexity low, allows other implementation details, and separates concerns. If you nevertheless find it useful for such purposes, rest assured that we find this incredibly cool even though we may not accept PRs to introduce additional complexity motivated solely by such use. Rather, use the code and free license to shape it to those other needs.


  • Canvas mutation to differently sized types blocked by ..
  • .. Rec logical mutations, keeping len but not byte_len
  • Relaxing internal Buf requirements to allow reuse of memory for f32 (only AsBytes but not FromBytes)
  • Use alignment for SIMD iteration/transmutation/map-operation
  • Ensure core::mem::needs_drop is false to provide better semantics for values.


~31K SLoC