W3cubDocs

/Rust

Trait std::ops::RemAssign

#[lang = "rem_assign"]
pub trait RemAssign<Rhs = Self> {
    fn rem_assign(&mut self, rhs: Rhs);
}

The remainder assignment operator %=.

Examples

use std::ops::RemAssign;

struct CookieJar { cookies: u32 }

impl RemAssign<u32> for CookieJar {
    fn rem_assign(&mut self, piles: u32) {
        self.cookies %= piles;
    }
}

let mut jar = CookieJar { cookies: 31 };
let piles = 4;

println!("Splitting up {} cookies into {} even piles!", jar.cookies, piles);

jar %= piles;

println!("{} cookies remain in the cookie jar!", jar.cookies);

Required Methods

Performs the %= operation.

Implementors

© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/ops/trait.RemAssign.html