pub struct SaveFile {
pub header: SaveHeader,
pub snapshot: WorldSnapshot,
pub checksum: u32,
}Expand description
A complete in-memory representation of a save file.
Call write_to_bytes() / write_to_file() to persist it.
Fields§
§header: SaveHeader§snapshot: WorldSnapshot§checksum: u32CRC-32 checksum of header + snapshot bytes. Computed lazily on write.
Implementations§
Source§impl SaveFile
impl SaveFile
pub fn new(snapshot: WorldSnapshot) -> Self
pub fn with_header(self, header: SaveHeader) -> Self
Sourcepub fn write_to_bytes(&mut self) -> Vec<u8> ⓘ
pub fn write_to_bytes(&mut self) -> Vec<u8> ⓘ
Serialize to a byte vector using the binary format described in the module doc.
Sourcepub fn write_to_file(&mut self, path: &str) -> Result<(), SaveError>
pub fn write_to_file(&mut self, path: &str) -> Result<(), SaveError>
Write the save file to disk at path.
Sourcepub fn read_from_bytes(bytes: &[u8]) -> Result<SaveFile, SaveError>
pub fn read_from_bytes(bytes: &[u8]) -> Result<SaveFile, SaveError>
Parse a SaveFile from raw bytes.
Sourcepub fn read_from_file(path: &str) -> Result<SaveFile, SaveError>
pub fn read_from_file(path: &str) -> Result<SaveFile, SaveError>
Read a SaveFile from a file on disk.
Sourcepub fn verify_checksum(&self) -> bool
pub fn verify_checksum(&self) -> bool
Re-compute the checksum and compare it with the stored value.
Auto Trait Implementations§
impl Freeze for SaveFile
impl RefUnwindSafe for SaveFile
impl Send for SaveFile
impl Sync for SaveFile
impl Unpin for SaveFile
impl UnsafeUnpin for SaveFile
impl UnwindSafe for SaveFile
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.