pub fn subtract_with_minimum(
        &mut self,
        key: &Address,
        req: &TokenAmount,
        floor: &TokenAmount,
    ) -> Result<TokenAmount, Box<dyn StdError>> {
        let prev = self.get(key)?;
        let available = prev
            .checked_sub(floor)
            .unwrap_or_else(|| TokenAmount::from(0u8));
        let sub: TokenAmount = std::cmp::min(&available, req).clone();

        if sub.is_positive() {
            self.add(key, &-sub.clone())?;
        }

        Ok(sub)
    }
/// Subtracts up to the specified amount from a balance, without reducing the balance
/// below some minimum.
/// Returns the amount subtracted (always positive or zero).
Subtracts up to the specified amount from a balance, without reducing the balance
below some minimum.
Returns the amount subtracted (always positive or zero).
Subtracts up to the specified amount from a balance without reducing the balance below some minimum . Returns the amount subtracted ( always positive or zero ) .
pub fn subtract_with_minimum(
        &mut self,
        key: &Address,
        req: &TokenAmount,
        floor: &TokenAmount,
    ) -> Result<TokenAmount, Box<dyn StdError>> {
        let prev = self.get(key)?;
        let available = prev
            .checked_sub(floor)
            .unwrap_or_else(|| TokenAmount::from(0u8));
        let sub: TokenAmount = std::cmp::min(&available, req).clone();
        if sub.is_positive() {
            self.add(key, &-sub.clone())?;
        }
        Ok(sub)
    }
pub fn subtract_with_minimum ( & mut self , key : & Address , req : & TokenAmount , floor : & TokenAmount , ) -> Result < TokenAmount , Box < dyn StdError > > { let prev = self . get ( key ) ? ; let available = prev . checked_sub ( floor ) . unwrap_or_else ( | | TokenAmount :: from ( 0u8 ) ) ; let sub : TokenAmount = std :: cmp :: min ( & available , req ) . clone ( ) ; if sub . is_positive ( ) { self . add ( key , & - sub . clone ( ) ) ? ; } Ok ( sub ) }
Subtracts up to the specified amount from a balance, without reducing the balance
below some minimum.
Subtracts up to the specified amount from a balance without reducing the balance below some minimum .
&mut self
key
&Address
req
&TokenAmount
floor
&TokenAmount