rust/vec2d/src/lib.rs
changeset 14702 29dbe9ce8b7d
parent 14350 31717e1436cd
child 15901 f39f0f614dbf
--- a/rust/vec2d/src/lib.rs	Thu Mar 21 01:23:05 2019 +0300
+++ b/rust/vec2d/src/lib.rs	Fri Mar 22 18:01:08 2019 +0200
@@ -95,6 +95,19 @@
         let width = self.width();
         self.data.chunks_exact_mut(width)
     }
+
+    #[inline]
+    pub unsafe fn as_bytes(&self) -> &[u8] {
+        use std::{
+            slice,
+            mem
+        };
+        
+        slice::from_raw_parts(
+            self.data.as_ptr() as *const u8,
+            self.data.len() * mem::size_of::<T>(),
+        )
+    }
 }
 
 impl<T: Copy> AsRef<[T]> for Vec2D<T> {