pub struct Sign(pub i128);Expand description
Sign of a number.
Tuple Fields§
§0: i128Trait Implementations§
Source§impl ChineseFormat for Sign
When converted to Chinese, a sign renders as follows:
impl ChineseFormat for Sign
When converted to Chinese, a sign renders as follows:
-
for positive numbers and zero: an empty string (thus omissible, too).
-
for negative numbers:
-
负in Variant::Simplified script. -
負in Variant::Traditional script.
-
use chinese_format::*;
//Positive numbers
assert_eq!(Sign(90).to_chinese(Variant::Simplified), Chinese {
logograms: "".to_string(),
omissible: true
});
assert_eq!(Sign(90).to_chinese(Variant::Traditional), "");
//Zero
assert_eq!(Sign(0).to_chinese(Variant::Simplified), Chinese {
logograms: "".to_string(),
omissible: true
});
assert_eq!(Sign(0).to_chinese(Variant::Traditional), "");
//Negative numbers
assert_eq!(Sign(-7).to_chinese(Variant::Simplified), Chinese {
logograms: "负".to_string(),
omissible: false
});
assert_eq!(Sign(-7).to_chinese(Variant::Traditional), "負");fn to_chinese(&self, variant: Variant) -> Chinese
Source§impl Hash for Sign
The hash depends uniquely on the sign of the underlying integer value.
impl Hash for Sign
The hash depends uniquely on the sign of the underlying integer value.
use chinese_format::*;
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
fn get_hash<T: Hash>(source: &T) -> u64 {
let mut hasher = DefaultHasher::new();
source.hash(&mut hasher);
hasher.finish()
}
fn main() {
assert_eq!(get_hash(&Sign(-54)), get_hash(&Sign(-7)));
assert_eq!(get_hash(&Sign(0)), get_hash(&Sign(0)));
assert_eq!(get_hash(&Sign(3)), get_hash(&Sign(90)));
assert_ne!(get_hash(&Sign(-54)), get_hash(&Sign(0)));
assert_ne!(get_hash(&Sign(0)), get_hash(&Sign(90)));
}Source§impl Ord for Sign
impl Ord for Sign
Source§impl PartialEq for Sign
Sign instances are equal if the sign (+, - or 0) of their
underlying numeric values are equal:
impl PartialEq for Sign
Sign instances are equal if the sign (+, - or 0) of their underlying numeric values are equal:
use chinese_format::*;
assert_eq!(Sign(-9), Sign(-3));
assert_eq!(Sign(0), Sign(0));
assert_eq!(Sign(13), Sign(90));
assert_ne!(Sign(-9), Sign(0));
assert_ne!(Sign(-9), Sign(7));
assert_ne!(Sign(0), Sign(-9));
assert_ne!(Sign(0), Sign(13));
assert_ne!(Sign(13), Sign(-9));
assert_ne!(Sign(13), Sign(0));Source§impl PartialOrd for Sign
Sign instances are sorted in this order:
impl PartialOrd for Sign
Sign instances are sorted in this order:
- negative
- zero
- positive
The magnitude of the underlying integer values does not affect the comparison:
use chinese_format::*;
assert!(Sign(-90) == Sign(-4));
assert!(Sign(0) > Sign(-4));
assert!(Sign(0) < Sign(17));
assert!(Sign(17) == Sign(92));impl Copy for Sign
impl Eq for Sign
Auto Trait Implementations§
impl Freeze for Sign
impl RefUnwindSafe for Sign
impl Send for Sign
impl Sync for Sign
impl Unpin for Sign
impl UnwindSafe for Sign
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