/// -Foo;
/// }
/// ```
+// NOTE(stage0): Remove trait after a snapshot
+#[cfg(stage0)]
#[lang="neg"]
pub trait Neg<Result> for Sized? {
/// The method for the unary `-` operator
fn neg(&self) -> Result;
}
+// NOTE(stage0): Remove macro after a snapshot
+#[cfg(stage0)]
macro_rules! neg_impl {
($($t:ty)*) => ($(
impl Neg<$t> for $t {
)*)
}
+// NOTE(stage0): Remove macro after a snapshot
+#[cfg(stage0)]
macro_rules! neg_uint_impl {
($t:ty, $t_signed:ty) => {
impl Neg<$t> for $t {
}
}
+/// The `Neg` trait is used to specify the functionality of unary `-`.
+///
+/// # Example
+///
+/// A trivial implementation of `Neg`. When `-Foo` happens, it ends up calling
+/// `neg`, and therefore, `main` prints `Negating!`.
+///
+/// ```
+/// struct Foo;
+///
+/// impl Copy for Foo {}
+///
+/// impl Neg<Foo> for Foo {
+/// fn neg(self) -> Foo {
+/// println!("Negating!");
+/// self
+/// }
+/// }
+///
+/// fn main() {
+/// -Foo;
+/// }
+/// ```
+#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
+#[lang="neg"]
+pub trait Neg<Result> {
+ /// The method for the unary `-` operator
+ fn neg(self) -> Result;
+}
+
+#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
+macro_rules! neg_impl {
+ ($($t:ty)*) => ($(
+ impl Neg<$t> for $t {
+ #[inline]
+ fn neg(self) -> $t { -self }
+ }
+ )*)
+}
+
+#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
+macro_rules! neg_uint_impl {
+ ($t:ty, $t_signed:ty) => {
+ impl Neg<$t> for $t {
+ #[inline]
+ fn neg(self) -> $t { -(self as $t_signed) as $t }
+ }
+ }
+}
+
neg_impl! { int i8 i16 i32 i64 f32 f64 }
neg_uint_impl! { uint, int }
/// !Foo;
/// }
/// ```
+// NOTE(stage0): Remove macro after a snapshot
+#[cfg(stage0)]
#[lang="not"]
pub trait Not<Result> for Sized? {
/// The method for the unary `!` operator
}
+// NOTE(stage0): Remove macro after a snapshot
+#[cfg(stage0)]
macro_rules! not_impl {
($($t:ty)*) => ($(
impl Not<$t> for $t {
)*)
}
+/// The `Not` trait is used to specify the functionality of unary `!`.
+///
+/// # Example
+///
+/// A trivial implementation of `Not`. When `!Foo` happens, it ends up calling
+/// `not`, and therefore, `main` prints `Not-ing!`.
+///
+/// ```
+/// struct Foo;
+///
+/// impl Copy for Foo {}
+///
+/// impl Not<Foo> for Foo {
+/// fn not(self) -> Foo {
+/// println!("Not-ing!");
+/// self
+/// }
+/// }
+///
+/// fn main() {
+/// !Foo;
+/// }
+/// ```
+#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
+#[lang="not"]
+pub trait Not<Result> {
+ /// The method for the unary `!` operator
+ fn not(self) -> Result;
+}
+
+#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
+macro_rules! not_impl {
+ ($($t:ty)*) => ($(
+ impl Not<$t> for $t {
+ #[inline]
+ fn not(self) -> $t { !self }
+ }
+ )*)
+}
+
not_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 }
/// The `BitAnd` trait is used to specify the functionality of `&`.