Skip to content

Commit 96bd6cf

Browse files
demonstrate RHS != Self use cases for Add and Sub
1 parent 11f8805 commit 96bd6cf

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
@@ -187,6 +187,12 @@ macro_rules! forward_ref_binop {
187187
/// Foo + Foo;
188188
/// }
189189
/// ```
190+
///
191+
/// Note that `RHS = Self` by default, but this is not mandatory. For example,
192+
/// [std::time::SystemTime] implements `Add<Duration>`, which permits
193+
/// operations of the form `SystemTime = SystemTime + Duration`.
194+
///
195+
/// [std::time::SystemTime]: ../../time/struct.SystemTime.html
190196
#[lang = "add"]
191197
#[stable(feature = "rust1", since = "1.0.0")]
192198
pub trait Add<RHS=Self> {
@@ -241,6 +247,12 @@ add_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
241247
/// Foo - Foo;
242248
/// }
243249
/// ```
250+
///
251+
/// Note that `RHS = Self` by default, but this is not mandatory. For example,
252+
/// [std::time::SystemTime] implements `Sub<Duration>`, which permits
253+
/// operations of the form `SystemTime = SystemTime - Duration`.
254+
///
255+
/// [std::time::SystemTime]: ../../time/struct.SystemTime.html
244256
#[lang = "sub"]
245257
#[stable(feature = "rust1", since = "1.0.0")]
246258
pub trait Sub<RHS=Self> {

0 commit comments

Comments
 (0)