EntryCmpByOptions

Struct EntryCmpByOptions 

Source
pub struct EntryCmpByOptions { /* private fields */ }
Expand description

A struct to compare two entries.

use std::cmp::Ordering;
use rspolib::{POEntry, EntryCmpByOptions};

let mut entry1 = POEntry::from("msgid 1");
let entry2 = POEntry::from("msgid 2");

let compare_by_all_fields = EntryCmpByOptions::new();
let compare_by_msgid_only = EntryCmpByOptions::new()
    .by_all(false)
    .by_msgid(true);

assert_eq!(entry1.cmp_by(&entry2, &compare_by_msgid_only), Ordering::Less);
assert_eq!(entry2.cmp_by(&entry1, &compare_by_msgid_only), Ordering::Greater);

entry1.msgid = "msgid 2".to_string();
assert_eq!(entry1.cmp_by(&entry2, &compare_by_msgid_only), Ordering::Equal);

entry1.msgstr = Some("msgstr 1".to_string());
assert_eq!(entry1.cmp_by(&entry2, &compare_by_msgid_only), Ordering::Equal);
assert_eq!(entry1.cmp_by(&entry2, &compare_by_all_fields), Ordering::Greater);

Implementations§

Source§

impl EntryCmpByOptions

Source

pub fn new() -> Self

Creates a instance of EntryCmpByOptions with comparisons for all fields enabled

Source

pub fn by_msgid(self, by_msgid: bool) -> Self

Source

pub fn by_msgstr(self, by_msgstr: bool) -> Self

Source

pub fn by_msgctxt(self, by_msgctxt: bool) -> Self

Source

pub fn by_obsolete(self, by_obsolete: bool) -> Self

Source

pub fn by_occurrences(self, by_occurrences: bool) -> Self

Source

pub fn by_msgid_plural(self, by_msgid_plural: bool) -> Self

Source

pub fn by_msgstr_plural(self, by_msgstr_plural: bool) -> Self

Source

pub fn by_flags(self, by_flags: bool) -> Self

Source

pub fn by_all(self, by_all: bool) -> Self

Trait Implementations§

Source§

impl Default for EntryCmpByOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<&Vec<(String, bool)>> for EntryCmpByOptions

Source§

fn from(options: &Vec<(String, bool)>) -> Self

Converts to this type from the input type.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.