pub struct Codec {
pub resources: Box<Vec<Resource>>,
}Expand description
Represents a collection of localized resources and provides methods to read, write, cache, and load these resources.
Fields§
§resources: Box<Vec<Resource>>The collection of resources managed by this codec.
Implementations§
Source§impl Codec
impl Codec
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, Resource>
pub fn iter_mut(&mut self) -> IterMut<'_, Resource>
Returns a mutable iterator over all resources.
Sourcepub fn get_by_language(&self, lang: &str) -> Option<&Resource>
pub fn get_by_language(&self, lang: &str) -> Option<&Resource>
Finds a resource by its language code, if present.
Sourcepub fn get_mut_by_language(&mut self, lang: &str) -> Option<&mut Resource>
pub fn get_mut_by_language(&mut self, lang: &str) -> Option<&mut Resource>
Finds a mutable resource by its language code, if present.
Sourcepub fn add_resource(&mut self, resource: Resource)
pub fn add_resource(&mut self, resource: Resource)
Adds a new resource to the collection.
Sourcepub fn read_file_by_type<P: AsRef<Path>>(
&mut self,
path: P,
format_type: FormatType,
) -> Result<(), Error>
pub fn read_file_by_type<P: AsRef<Path>>( &mut self, path: P, format_type: FormatType, ) -> Result<(), Error>
Sourcepub fn read_file_by_extension<P: AsRef<Path>>(
&mut self,
path: P,
lang: Option<String>,
) -> Result<(), Error>
pub fn read_file_by_extension<P: AsRef<Path>>( &mut self, path: P, lang: Option<String>, ) -> Result<(), Error>
Reads a resource file by inferring its format from the file extension. Optionally infers language from the path if not provided.
§Parameters
path: Path to the resource file.lang: Optional language code to use.
§Returns
Ok(()) if the file was successfully read,
or an Error if the format is unsupported or reading fails.
Sourcepub fn write_to_file(&self) -> Result<(), Error>
pub fn write_to_file(&self) -> Result<(), Error>
Writes all managed resources back to their respective files, grouped by domain.
§Returns
Ok(()) if all writes succeed, or an Error otherwise.
Auto Trait Implementations§
impl Freeze for Codec
impl RefUnwindSafe for Codec
impl Send for Codec
impl Sync for Codec
impl Unpin for Codec
impl UnwindSafe for Codec
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