Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infallible version of fetch_update #490

Closed
dev-ardi opened this issue Nov 19, 2024 · 2 comments
Closed

Infallible version of fetch_update #490

dev-ardi opened this issue Nov 19, 2024 · 2 comments
Labels
ACP-accepted API Change Proposal is accepted (seconded with no objections) api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api

Comments

@dev-ardi
Copy link

dev-ardi commented Nov 19, 2024

Proposal

Problem statement

fetch_update requires you to return an Option and handle the Err case. Sometimes you don't need to do that

Motivating examples or use cases

        my_atomic
            .fetch_update(Ordering::SeqCst, Ordering::SeqCst, |current| {
                Some(current + 10 % 50)
            })
            .expect("This can't return None");

Solution sketch

An alternative infallible function that doesn't require that:

    pub fn infallible_fetch_update<F>( // Name TBD
        &self,
        set_order: Ordering,
        fetch_order: Ordering,
        mut f: F,
    ) -> u64
    where
        F: FnMut(u64) -> u64,

Links and related work

https://rust-lang.zulipchat.com/#narrow/channel/327149-t-libs-api.2Fapi-changes/topic/Atomics.20fetch_update.20is.20awkward

What happens now?

This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.

Possible responses

The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):

  • We think this problem seems worth solving, and the standard library might be the right place to solve it.
  • We think that this probably doesn't belong in the standard library.

Second, if there's a concrete solution:

  • We think this specific solution looks roughly right, approved, you or someone else should implement this. (Further review will still happen on the subsequent implementation PR.)
  • We're not sure this is the right solution, and the alternatives or other materials don't give us enough information to be sure about that. Here are some questions we have that aren't answered, or rough ideas about alternatives we'd want to see discussed.
@dev-ardi dev-ardi added api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api labels Nov 19, 2024
@GrigorenkoPV
Copy link

Bikeshed: fetch_update_infallible

@Amanieu
Copy link
Member

Amanieu commented Dec 3, 2024

We discussed this in the libs-api meeting: we're happy to accept this as fetch_update_infallible. We're not huge fans of the name but couldn't think of anything better (ideallly fetch_update should have been called try_fetch_update, but that ship has sailed).

@Amanieu Amanieu closed this as completed Dec 3, 2024
@Amanieu Amanieu added the ACP-accepted API Change Proposal is accepted (seconded with no objections) label Dec 3, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 28, 2025
…le, r=Noratrieb

Implement `AtomicT::update` & `AtomicT::try_update`

ACP accepted in rust-lang/libs-team#490

`@rustbot` label +T-libs-api
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 28, 2025
…le, r=Noratrieb

Implement `AtomicT::update` & `AtomicT::try_update`

ACP accepted in rust-lang/libs-team#490

``@rustbot`` label +T-libs-api
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 28, 2025
Rollup merge of rust-lang#133829 - GrigorenkoPV:fetch_update_infallible, r=Noratrieb

Implement `AtomicT::update` & `AtomicT::try_update`

ACP accepted in rust-lang/libs-team#490

``@rustbot`` label +T-libs-api
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Jan 29, 2025
…atrieb

Implement `AtomicT::update` & `AtomicT::try_update`

ACP accepted in rust-lang/libs-team#490

``@rustbot`` label +T-libs-api
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ACP-accepted API Change Proposal is accepted (seconded with no objections) api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api
Projects
None yet
Development

No branches or pull requests

3 participants