Rollup merge of #35793 - matthew-piziak:add-rhs-example, r=steveklabnik
demonstrate `RHS != Self` use cases for `Add` and `Sub`
This commit is contained in:
commit
c330376a4d
1 changed files with 12 additions and 0 deletions
|
@ -282,6 +282,12 @@ macro_rules! forward_ref_binop {
|
||||||
/// Point { x: 3, y: 3 });
|
/// Point { x: 3, y: 3 });
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// Note that `RHS = Self` by default, but this is not mandatory. For example,
|
||||||
|
/// [std::time::SystemTime] implements `Add<Duration>`, which permits
|
||||||
|
/// operations of the form `SystemTime = SystemTime + Duration`.
|
||||||
|
///
|
||||||
|
/// [std::time::SystemTime]: ../../std/time/struct.SystemTime.html
|
||||||
#[lang = "add"]
|
#[lang = "add"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub trait Add<RHS=Self> {
|
pub trait Add<RHS=Self> {
|
||||||
|
@ -349,6 +355,12 @@ add_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
|
||||||
/// Point { x: 1, y: 0 });
|
/// Point { x: 1, y: 0 });
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// Note that `RHS = Self` by default, but this is not mandatory. For example,
|
||||||
|
/// [std::time::SystemTime] implements `Sub<Duration>`, which permits
|
||||||
|
/// operations of the form `SystemTime = SystemTime - Duration`.
|
||||||
|
///
|
||||||
|
/// [std::time::SystemTime]: ../../std/time/struct.SystemTime.html
|
||||||
#[lang = "sub"]
|
#[lang = "sub"]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub trait Sub<RHS=Self> {
|
pub trait Sub<RHS=Self> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue