File tree Expand file tree Collapse file tree 1 file changed +0
-21
lines changed
Expand file tree Collapse file tree 1 file changed +0
-21
lines changed Original file line number Diff line number Diff line change 1414//! implement comparison operators. Rust programs may implement `PartialOrd` to overload the `<`,
1515//! `<=`, `>`, and `>=` operators, and may implement `PartialEq` to overload the `==` and `!=`
1616//! operators.
17- //!
18- //! For example, to define a type with a customized definition for the PartialEq operators, you
19- //! could do the following:
20- //!
21- //! ```
22- //! # #![feature(core)]
23- //! struct FuzzyNum {
24- //! num: i32,
25- //! }
26- //!
27- //! impl PartialEq for FuzzyNum {
28- //! // Our custom eq allows numbers which are near each other to be equal! :D
29- //! fn eq(&self, other: &FuzzyNum) -> bool {
30- //! (self.num - other.num).abs() < 5
31- //! }
32- //! }
33- //!
34- //! // Now these binary operators will work when applied!
35- //! assert!(FuzzyNum { num: 37 } == FuzzyNum { num: 34 });
36- //! assert!(FuzzyNum { num: 25 } != FuzzyNum { num: 57 });
37- //! ```
3817
3918#![ stable( feature = "rust1" , since = "1.0.0" ) ]
4019
You can’t perform that action at this time.
0 commit comments