Re: [PATCH] rust: atomic: add fetch_sub
From: Gary Guo
Date: Wed Jan 28 2026 - 09:28:58 EST
On Wed Jan 28, 2026 at 2:16 PM GMT, Andreas Hindborg wrote:
> "Alice Ryhl" <aliceryhl@xxxxxxxxxx> writes:
>
>> On Wed, Jan 28, 2026 at 01:47:11PM +0100, Andreas Hindborg wrote:
>>> Add `Atomic::fetch_sub` with implementation and documentation in line with
>>> existing `Atomic::fetch_add` implementation.
>>>
>>> Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
>>
>>> + /// let x = Atomic::new(42);
>>> + ///
>>> + /// assert_eq!(42, x.load(Relaxed));
>>> + ///
>>> + /// assert_eq!(30, { x.fetch_sub(12, Acquire); x.load(Relaxed) });
>>
>> These asserts are a bit confusing to read. After all, the fetch_sub call
>> also returns a value, so how about this?
>>
>> let x = Atomic::new(42);
>> assert_eq!(42, x.load(Relaxed));
>> assert_eq!(42, x.fetch_sub(12, Acquire));
>> assert_eq!(30, x.load(Relaxed));
>
> We can do that. I basically copied the docs from add. Should I change
> those as well?
Please do. I also find that the existing example has too many line breaks :)
Something compact as what Alice suggested would be nice.
Best,
Gary
>
> Best regards,
> Andreas Hindborg