mirror of
https://github.com/bevyengine/bevy
synced 2025-01-27 20:35:21 +00:00
30 lines
692 B
Rust
30 lines
692 B
Rust
|
use zerocopy::AsBytes;
|
||
|
use crate::math::Vec4;
|
||
|
|
||
|
pub trait GetBytes {
|
||
|
fn get_bytes(&self) -> Vec<u8>;
|
||
|
fn get_bytes_ref(&self) -> Option<&[u8]>;
|
||
|
}
|
||
|
|
||
|
// TODO: might need to add zerocopy to this crate to impl AsBytes for external crates
|
||
|
// impl<T> GetBytes for T where T : AsBytes {
|
||
|
// fn get_bytes(&self) -> Vec<u8> {
|
||
|
// self.as_bytes().into()
|
||
|
// }
|
||
|
|
||
|
// fn get_bytes_ref(&self) -> Option<&[u8]> {
|
||
|
// Some(self.as_bytes())
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
impl GetBytes for Vec4 {
|
||
|
fn get_bytes(&self) -> Vec<u8> {
|
||
|
let vec4_array: [f32; 4] = (*self).into();
|
||
|
vec4_array.as_bytes().into()
|
||
|
}
|
||
|
|
||
|
fn get_bytes_ref(&self) -> Option<&[u8]> {
|
||
|
None
|
||
|
}
|
||
|
}
|