Skip to content

Commit 2908ab2

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#35793 - matthew-piziak:add-rhs-example, r=steveklabnik
demonstrate `RHS != Self` use cases for `Add` and `Sub`
2 parents 23ef388 + 9a400f0 commit 2908ab2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/libcore/ops.rs

+12
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ macro_rules! forward_ref_binop {
282282
/// Point { x: 3, y: 3 });
283283
/// }
284284
/// ```
285+
///
286+
/// Note that `RHS = Self` by default, but this is not mandatory. For example,
287+
/// [std::time::SystemTime] implements `Add<Duration>`, which permits
288+
/// operations of the form `SystemTime = SystemTime + Duration`.
289+
///
290+
/// [std::time::SystemTime]: ../../std/time/struct.SystemTime.html
285291
#[lang = "add"]
286292
#[stable(feature = "rust1", since = "1.0.0")]
287293
pub trait Add<RHS=Self> {
@@ -349,6 +355,12 @@ add_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
349355
/// Point { x: 1, y: 0 });
350356
/// }
351357
/// ```
358+
///
359+
/// Note that `RHS = Self` by default, but this is not mandatory. For example,
360+
/// [std::time::SystemTime] implements `Sub<Duration>`, which permits
361+
/// operations of the form `SystemTime = SystemTime - Duration`.
362+
///
363+
/// [std::time::SystemTime]: ../../std/time/struct.SystemTime.html
352364
#[lang = "sub"]
353365
#[stable(feature = "rust1", since = "1.0.0")]
354366
pub trait Sub<RHS=Self> {

0 commit comments

Comments
 (0)