pub struct Storage { /* private fields */ }Expand description
The game’s data folder.
Implementations§
Source§impl Storage
impl Storage
Sourcepub fn for_game(game: &str) -> Self
pub fn for_game(game: &str) -> Self
The standard folder for a game: %APPDATA%/Kvas/<game> on Windows, ~/.local/share/kvas/<game> elsewhere.
Sourcepub fn save(&self, slot: &str, title: &str, data: &Value) -> Result<(), String>
pub fn save(&self, slot: &str, title: &str, data: &Value) -> Result<(), String>
Writes a save slot. title is what a load menu shows.
Sourcepub fn save_as<T: Serialize>(
&self,
slot: &str,
title: &str,
value: &T,
) -> Result<(), String>
pub fn save_as<T: Serialize>( &self, slot: &str, title: &str, value: &T, ) -> Result<(), String>
Typed save: any Serialize value.
Sourcepub fn load_as<T: for<'de> Deserialize<'de>>(&self, slot: &str) -> Option<T>
pub fn load_as<T: for<'de> Deserialize<'de>>(&self, slot: &str) -> Option<T>
Typed load.
Sourcepub fn set_setting(&self, key: &str, value: Value) -> Result<(), String>
pub fn set_setting(&self, key: &str, value: Value) -> Result<(), String>
Changes one setting and writes the file.
Sourcepub fn read_text(&self, rel: &str) -> Result<String, String>
pub fn read_text(&self, rel: &str) -> Result<String, String>
Reads a text file of the data folder.
Sourcepub fn write_text(&self, rel: &str, text: &str) -> Result<(), String>
pub fn write_text(&self, rel: &str, text: &str) -> Result<(), String>
Writes a text file (folders are created).
Sourcepub fn write_bytes(&self, rel: &str, bytes: &[u8]) -> Result<(), String>
pub fn write_bytes(&self, rel: &str, bytes: &[u8]) -> Result<(), String>
Writes bytes (folders are created).
Sourcepub fn append_line(&self, rel: &str, line: &str) -> Result<(), String>
pub fn append_line(&self, rel: &str, line: &str) -> Result<(), String>
Appends a line (logs, statistics).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Storage
impl RefUnwindSafe for Storage
impl Send for Storage
impl Sync for Storage
impl Unpin for Storage
impl UnsafeUnpin for Storage
impl UnwindSafe for Storage
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> MaybeSync for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.