Struct rspolib::MOFile

source ·
pub struct MOFile {
    pub magic_number: Option<u32>,
    pub version: Option<u32>,
    pub metadata: HashMap<String, String>,
    pub entries: Vec<MOEntry>,
    pub options: FileOptions,
}
Expand description

MO file

Fields§

§magic_number: Option<u32>

Magic number, either MAGIC or MAGIC_SWAPPED

§version: Option<u32>

Version number, either 0 or 1

§metadata: HashMap<String, String>

Metadata as a hash map

§entries: Vec<MOEntry>

Message entries

§options: FileOptions

File options. See FileOptions.

Implementations§

source§

impl MOFile

source

pub fn new(options: FileOptions) -> Self

source

pub fn metadata_as_entry(&self) -> MOEntry

Returns the metadata as a MOEntry

source

pub fn find( &self, value: &str, by: &str, msgctxt: Option<&str> ) -> Vec<&MOEntry>

Find entries by a given field and value

The field defined in the by argument can be one of:

  • msgid
  • msgstr
  • msgctxt
  • msgid_plural

Passing the optional msgctxt argument the entry will also must match with the given context.

source

pub fn find_by_msgid(&self, msgid: &str) -> Option<&MOEntry>

Find an entry by msgid

source

pub fn find_by_msgid_msgctxt( &self, msgid: &str, msgctxt: &str ) -> Option<&MOEntry>

Find an entry by msgid and msgctxt

source

pub fn remove(&mut self, entry: &MOEntry)

Remove an entry from the file

source

pub fn remove_by_msgid(&mut self, msgid: &str)

Remove the first entry that has the same msgid

source

pub fn remove_by_msgid_msgctxt(&mut self, msgid: &str, msgctxt: &str)

Remove the first entry that has the same msgid and msgctxt

source

pub fn as_bytes_with( &self, magic_number: u32, revision_number: u32 ) -> Cow<'_, [u8]>

Returns the entry as a bytes vector

Specify the magic number and the revision number of the generated MO version of the file.

This method does not check the validity of the values magic_number and revision_version to allow the experimental developing of other revision of MO files, so be careful about the passed values if you use it.

Valid values for the magic number are MAGIC and MAGIC_SWAPPED. Valid values for the revision number are 0 and 1.

Example
use rspolib::mofile;

let file = mofile("tests-data/all.mo").unwrap();
let bytes = file.as_bytes_with(rspolib::MAGIC_SWAPPED, 1);
assert_eq!(bytes.len(), 1327);

Trait Implementations§

source§

impl AsBytes for MOFile

source§

fn as_bytes(&self) -> Cow<'_, [u8]>

Return the MOFile as a vector of bytes in little endian

source§

fn as_bytes_le(&self) -> Cow<'_, [u8]>

Return the MOFile as a vector of bytes in little endian

source§

fn as_bytes_be(&self) -> Cow<'_, [u8]>

Return the MOFile as a vector of bytes in big endian

source§

impl Clone for MOFile

source§

fn clone(&self) -> MOFile

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for MOFile

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for MOFile

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&POFile> for MOFile

source§

fn from(file: &POFile) -> MOFile

Converts to this type from the input type.
source§

impl From<&Path> for MOFile

source§

fn from(path: &Path) -> Self

Converts to this type from the input type.
source§

impl From<Vec<&MOEntry>> for MOFile

source§

fn from(entries: Vec<&MOEntry>) -> Self

Converts to this type from the input type.
source§

impl PartialEq for MOFile

source§

fn eq(&self, other: &MOFile) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Save for MOFile

source§

fn save(&self, path: &str)

Save the MOFile to a file at the given path

source§

impl SaveAsMOFile for MOFile

source§

fn save_as_mofile(&self, path: &str)

Save the MOFile to a file at the given path

source§

impl SaveAsPOFile for MOFile

source§

fn save_as_pofile(&self, path: &str)
where Self: Display,

Save the file as a PO file to the given path
source§

impl StructuralPartialEq for MOFile

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.