-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix the error message according to singular or even (#769)
* fix: fix the error message according to singular or even Signed-off-by: zongz <[email protected]> * fix: make fmt Signed-off-by: zongz <[email protected]> * fix: move error message generation to compiler_base_error Signed-off-by: zongz <[email protected]> --------- Signed-off-by: zongz <[email protected]>
- Loading branch information
Showing
7 changed files
with
63 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//! This file provides some of the self-encapsulated types used in handling error messages. | ||
/// [`TyeWithUnit`] is a trait for types that can be converted into a string with a unit. | ||
pub trait TypeWithUnit { | ||
fn into_string_with_unit(self) -> String; | ||
} | ||
|
||
/// [`UnitUsize`] is a [`usize`] type that can be converted into a string with a unit. | ||
pub struct UnitUsize(pub usize, pub String); | ||
|
||
impl TypeWithUnit for UnitUsize { | ||
/// [`into_string_with_unit`] converts [`UnitUsize`] into a string with a unit. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// use compiler_base_error::unit_type::{TypeWithUnit, UnitUsize}; | ||
/// | ||
/// let unit_usize = UnitUsize(1, "byte".to_string()); | ||
/// assert_eq!(unit_usize.into_string_with_unit(), "1 byte"); | ||
/// let unit_usize = UnitUsize(2, "byte".to_string()); | ||
/// assert_eq!(unit_usize.into_string_with_unit(), "2 bytes"); | ||
/// ``` | ||
fn into_string_with_unit(self) -> String { | ||
if self.0 > 1 { | ||
format!("{} {}s", self.0, self.1) | ||
} else { | ||
format!("{} {}", self.0, self.1) | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters