Skip to content

Commit dfce548

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 fc7c26f + 9a400f0 commit dfce548

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
@@ -302,6 +302,12 @@ macro_rules! forward_ref_binop {
302302
/// Point { x: 3, y: 3 });
303303
/// }
304304
/// ```
305+
///
306+
/// Note that `RHS = Self` by default, but this is not mandatory. For example,
307+
/// [std::time::SystemTime] implements `Add<Duration>`, which permits
308+
/// operations of the form `SystemTime = SystemTime + Duration`.
309+
///
310+
/// [std::time::SystemTime]: ../../std/time/struct.SystemTime.html
305311
#[lang = "add"]
306312
#[stable(feature = "rust1", since = "1.0.0")]
307313
pub trait Add<RHS=Self> {
@@ -369,6 +375,12 @@ add_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
369375
/// Point { x: 1, y: 0 });
370376
/// }
371377
/// ```
378+
///
379+
/// Note that `RHS = Self` by default, but this is not mandatory. For example,
380+
/// [std::time::SystemTime] implements `Sub<Duration>`, which permits
381+
/// operations of the form `SystemTime = SystemTime - Duration`.
382+
///
383+
/// [std::time::SystemTime]: ../../std/time/struct.SystemTime.html
372384
#[lang = "sub"]
373385
#[stable(feature = "rust1", since = "1.0.0")]
374386
pub trait Sub<RHS=Self> {

0 commit comments

Comments
 (0)