Skip to content

Commit

Permalink
Merge pull request #13 from qwandor/derive
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettDong authored Jul 4, 2024
2 parents 26e0a4e + 862635a commit 7f8215c
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/catalog/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::message::{
CatalogMessageMutView, Message, MessageFlags, MessageKey, MessageMutView, MessageView,
SingularPluralMismatchError,
};
use std::fmt::{self, Debug, Formatter};

pub struct CatalogMessageRef<C> {
catalog: C,
Expand Down Expand Up @@ -94,6 +95,12 @@ impl<'a> MessageMutProxy<'a> {
}
}

impl<'a> Debug for MessageMutProxy<'a> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
self.message().fmt(f)
}
}

impl<'a> MessageView for MessageMutProxy<'a> {
fn is_singular(&self) -> bool {
self.message().is_singular()
Expand Down
1 change: 1 addition & 0 deletions src/catalog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub use iterator::{Iter, IterMut, MessageMutProxy};
use std::collections::btree_map::BTreeMap;

/// `Catalog` struct represents a collection of _Messages_ stored in a `.po` or `.mo` file.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Catalog {
/// Metadata of the catalog.
pub metadata: CatalogMetadata,
Expand Down
1 change: 1 addition & 0 deletions src/message/builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::message::{Message, MessageFlags};

/// A helper type to build a `Message` conveniently via method chaining.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MessageBuilder {
m: Message,
}
Expand Down
2 changes: 1 addition & 1 deletion src/message/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fmt::{Display, Formatter};
use std::str::FromStr;

/// Represents the set of flags in a message
#[derive(Debug, Clone)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MessageFlags {
/// Vector of individual flags
pub entries: Vec<String>,
Expand Down
2 changes: 1 addition & 1 deletion src/message/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::message::{Message, MessageView};
use concat_string::concat_string;

#[derive(PartialEq, Eq, PartialOrd, Ord)]
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub(crate) struct MessageKey {
key: String,
}
Expand Down
2 changes: 1 addition & 1 deletion src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) use key::MessageKey;
pub use view::{CatalogMessageMutView, MessageMutView, MessageView, SingularPluralMismatchError};

/// Represents a single message entry.
#[derive(Debug, Default)]
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct Message {
/// Developer comments of the message.
pub(crate) comments: String,
Expand Down
2 changes: 1 addition & 1 deletion src/message/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::fmt::{Display, Formatter};
use crate::message::{Message, MessageFlags};

/// Error type when trying to access a field that is not applicable to the plural type of the message.
#[derive(Debug)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SingularPluralMismatchError;

impl Display for SingularPluralMismatchError {
Expand Down
4 changes: 2 additions & 2 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::collections::HashMap;
use crate::plural::*;

/// Metadata of a translation catalog.
#[derive(Default)]
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct CatalogMetadata {
/// `Project-Id-Version`
pub project_id_version: String,
Expand All @@ -30,7 +30,7 @@ pub struct CatalogMetadata {
}

/// Error in parsing metadata of a catalog
#[derive(Debug)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MetadataParseError {
message: String,
}
Expand Down
3 changes: 2 additions & 1 deletion src/plural.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// The plural form resolution rule of the target language.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct CatalogPluralRules {
/// Total number of plural forms, including singular form.
pub nplurals: usize,
Expand All @@ -16,7 +17,7 @@ impl Default for CatalogPluralRules {
}

/// Error type when parsing an invalid plural rules.
#[derive(Debug)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PluralRulesError {
message: String,
}
Expand Down
4 changes: 2 additions & 2 deletions src/po_file/po_file_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::path::Path;
use std::str::{FromStr, Utf8Error};

/// PO file parse options.
#[derive(Clone, Copy, Default)]
#[derive(Copy, Clone, Default, Eq, PartialEq)]
pub struct POParseOptions {
/// If true, only parse msgctxt, msgid and msgstr.
pub message_body_only: bool,
Expand All @@ -31,7 +31,7 @@ impl POParseOptions {
}

/// Error in parsing a PO file
#[derive(Debug)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct POParseError {
message: String,
}
Expand Down

0 comments on commit 7f8215c

Please sign in to comment.