File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -358,11 +358,32 @@ impl PartialOrd for Ordering {
358
358
/// If your type is `Ord`, you can implement `partial_cmp()` by using `cmp()`:
359
359
///
360
360
/// ```
361
+ /// use std::cmp::Ordering;
362
+ ///
363
+ /// #[derive(Eq)]
364
+ /// struct Person {
365
+ /// id: u32,
366
+ /// name: String,
367
+ /// height: u32,
368
+ /// }
369
+ ///
361
370
/// impl PartialOrd for Person {
362
371
/// fn partial_cmp(&self, other: &Person) -> Option<Ordering> {
363
372
/// Some(self.cmp(other))
364
373
/// }
365
374
/// }
375
+ ///
376
+ /// impl Ord for Person {
377
+ /// fn cmp(&self, other: &Person) -> Ordering {
378
+ /// self.height.cmp(&other.height)
379
+ /// }
380
+ /// }
381
+ ///
382
+ /// impl PartialEq for Person {
383
+ /// fn eq(&self, other: &Person) -> bool {
384
+ /// self.height == other.height
385
+ /// }
386
+ /// }
366
387
/// ```
367
388
///
368
389
/// You may also find it useful to use `partial_cmp()` on your type`s fields. Here
You can’t perform that action at this time.
0 commit comments