pub struct ChunkSerializer;Expand description
Serializes/deserializes chunks to/from a binary format.
Format:
[magic: u32][version: u16][coord_x: i32][coord_z: i32]
[timestamp: u64][seed: u64][lod: u8]
[heightmap_width: u32][heightmap_height: u32][heightmap_data: f32 * w * h]
[checksum: u32]Implementations§
Source§impl ChunkSerializer
impl ChunkSerializer
Sourcepub fn deserialize(bytes: &[u8]) -> Option<TerrainChunk>
pub fn deserialize(bytes: &[u8]) -> Option<TerrainChunk>
Deserialize a chunk from bytes. Returns None if format is invalid.
Sourcepub fn save_to_file(chunk: &TerrainChunk, path: &str) -> Result<(), String>
pub fn save_to_file(chunk: &TerrainChunk, path: &str) -> Result<(), String>
Save chunk to a file path (returns error string on failure).
Sourcepub fn load_from_file(path: &str) -> Result<TerrainChunk, String>
pub fn load_from_file(path: &str) -> Result<TerrainChunk, String>
Load chunk from a file path.
Auto Trait Implementations§
impl Freeze for ChunkSerializer
impl RefUnwindSafe for ChunkSerializer
impl Send for ChunkSerializer
impl Sync for ChunkSerializer
impl Unpin for ChunkSerializer
impl UnsafeUnpin for ChunkSerializer
impl UnwindSafe for ChunkSerializer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.