Skip to main content

Ring

Trait Ring 

Source
pub trait Ring: Semiring {
    // Required method
    fn subtract(a: Self, b: Self) -> Self;
}
Expand description

A type class for types that extend Semiring with subtraction.

§Laws

  • Additive inverse: subtract(a, a) = zero
  • Compatibility: subtract(a, b) = add(a, negate(b))

§Examples

use fp_library::classes::{
	Ring,
	Semiring,
};

// Additive inverse: subtract(a, a) = zero
assert_eq!(i32::subtract(5, 5), i32::zero());

Required Methods§

Source

fn subtract(a: Self, b: Self) -> Self

Subtracts the second value from the first.

§Type Signature

(Self, Self) -> Self

§Parameters
  • a: The value to subtract from.
  • b: The value to subtract.
§Returns

The difference.

§Examples
use fp_library::classes::Ring;

assert_eq!(i32::subtract(5, 3), 2);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Ring for f32

Source§

fn subtract(a: Self, b: Self) -> Self

Subtracts using the - operator.

§Type Signature

(Self, Self) -> Self

§Parameters
  • a: The value to subtract from.
  • b: The value to subtract.
§Returns

The difference.

§Examples
use fp_library::classes::Ring;

assert_eq!(<f32>::subtract(5.0 as f32, 3.0 as f32), 2.0 as f32);
Source§

impl Ring for f64

Source§

fn subtract(a: Self, b: Self) -> Self

Subtracts using the - operator.

§Type Signature

(Self, Self) -> Self

§Parameters
  • a: The value to subtract from.
  • b: The value to subtract.
§Returns

The difference.

§Examples
use fp_library::classes::Ring;

assert_eq!(<f64>::subtract(5.0 as f64, 3.0 as f64), 2.0 as f64);
Source§

impl Ring for i8

Source§

fn subtract(a: Self, b: Self) -> Self

Subtracts using wrapping subtraction.

§Type Signature

(Self, Self) -> Self

§Parameters
  • a: The value to subtract from.
  • b: The value to subtract.
§Returns

The difference (wrapping on overflow).

§Examples
use fp_library::classes::Ring;

assert_eq!(<i8>::subtract(5 as i8, 3 as i8), 2 as i8);
Source§

impl Ring for i16

Source§

fn subtract(a: Self, b: Self) -> Self

Subtracts using wrapping subtraction.

§Type Signature

(Self, Self) -> Self

§Parameters
  • a: The value to subtract from.
  • b: The value to subtract.
§Returns

The difference (wrapping on overflow).

§Examples
use fp_library::classes::Ring;

assert_eq!(<i16>::subtract(5 as i16, 3 as i16), 2 as i16);
Source§

impl Ring for i32

Source§

fn subtract(a: Self, b: Self) -> Self

Subtracts using wrapping subtraction.

§Type Signature

(Self, Self) -> Self

§Parameters
  • a: The value to subtract from.
  • b: The value to subtract.
§Returns

The difference (wrapping on overflow).

§Examples
use fp_library::classes::Ring;

assert_eq!(<i32>::subtract(5 as i32, 3 as i32), 2 as i32);
Source§

impl Ring for i64

Source§

fn subtract(a: Self, b: Self) -> Self

Subtracts using wrapping subtraction.

§Type Signature

(Self, Self) -> Self

§Parameters
  • a: The value to subtract from.
  • b: The value to subtract.
§Returns

The difference (wrapping on overflow).

§Examples
use fp_library::classes::Ring;

assert_eq!(<i64>::subtract(5 as i64, 3 as i64), 2 as i64);
Source§

impl Ring for i128

Source§

fn subtract(a: Self, b: Self) -> Self

Subtracts using wrapping subtraction.

§Type Signature

(Self, Self) -> Self

§Parameters
  • a: The value to subtract from.
  • b: The value to subtract.
§Returns

The difference (wrapping on overflow).

§Examples
use fp_library::classes::Ring;

assert_eq!(<i128>::subtract(5 as i128, 3 as i128), 2 as i128);
Source§

impl Ring for isize

Source§

fn subtract(a: Self, b: Self) -> Self

Subtracts using wrapping subtraction.

§Type Signature

(Self, Self) -> Self

§Parameters
  • a: The value to subtract from.
  • b: The value to subtract.
§Returns

The difference (wrapping on overflow).

§Examples
use fp_library::classes::Ring;

assert_eq!(<isize>::subtract(5 as isize, 3 as isize), 2 as isize);

Implementors§