File tree 1 file changed +0
-21
lines changed
1 file changed +0
-21
lines changed Original file line number Diff line number Diff line change 14
14
//! implement comparison operators. Rust programs may implement `PartialOrd` to overload the `<`,
15
15
//! `<=`, `>`, and `>=` operators, and may implement `PartialEq` to overload the `==` and `!=`
16
16
//! 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
- //! ```
38
17
39
18
#![ stable( feature = "rust1" , since = "1.0.0" ) ]
40
19
You can’t perform that action at this time.
0 commit comments