Skip to content

Conversation

@yoshuawuyts
Copy link
Member

Tracking issue: #144426

One of the open questions blocking the stabilization of DropGuard is what to name the associated method that prevents the destructor from running, and returns the captured value. This method is currently called into_inner, but most people (including myself) feel like this would benefit from a method that calls more attention to itself.

This PR proposes naming this method dismiss, after the Linux kernel's ScopeGuard::dismiss. Which crucially does not evoke images of violence or weaponry the way alternatives such as "disarm" or "defuse" do. And personally I enjoy the visual metaphor of "dismissing a guard" (e.g. a person keeping watch over something) - a job well done, they're free to go.

This PR also changes the signature from an static method to an instance method. This also matches the Linux kernel's API, and seems alright since dismiss is not nearly as ubiquitous as into_inner. This makes it more convenient to use, with a much lower risk of conflicting. Though in the rare case there might be ambiguity, the explicit notation is available as a fallback.

let x = DropGuard::into_inner(guard);  // ← current
let x = guard.dismiss();               // ← proposed

Also changes it from a static method to an instance method.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 6, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 6, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rust-log-analyzer

This comment has been minimized.

@hkBst
Copy link
Member

hkBst commented Nov 7, 2025

Some alternative options (since I did not see any yet):

  • unwrap
  • yield
  • leave
  • give
  • take
  • release
  • unguard
  • deliver

@yoshuawuyts
Copy link
Member Author

In the tracking issue, ACP, impl PR, and libs-api meeting the following options were brought up as well: disarm, defuse, disable, and skip_drop. Let me cover my thinking on all options here:

  • disarm: references weaponry, and I'd rather we not.
  • defuse: references explosives, same thing.
  • disable: If we think of a "guard" as a person standing watch, "disabling" them reads pretty aggro.
  • skip_drop: Is imo too verbose; I much prefer single verbs.
  • unwrap: Will get us into trouble with DropGuard<Option<T>> if we make it an instance method.
  • take: Same as unwrap.
  • yield: Is a reserved keyword.
  • give: Has the wrong polarity: if we take from the guard, we should give to the guard.

That leaves us with: dismiss, leave, release, unguard, and deliver. Out of these I still like dismiss best I think, but I'd be happy with release as well. For me it's a toss-up between those two.

@Mark-Simulacrum Mark-Simulacrum added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Nov 9, 2025
@Mark-Simulacrum
Copy link
Member

I assume libs-api nominated is appropriate?

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-t-libs-api Status: Awaiting decision from T-libs-api and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 9, 2025
@yoshuawuyts
Copy link
Member Author

Yes, that's great - thank you!

@hkBst
Copy link
Member

hkBst commented Nov 9, 2025

@yoshuawuyts If a guard guards a thing and you dismiss them, what happens with the thing? I guess it depends on how big/heavy the thing is. I think I like deliver and release because they align more with the imagery of the guard going away, but leaving the thing. With dismiss it sounds like the thing could be going away with the guard. In that light let me propose some more options:

  • regain
  • recover
  • reclaim
  • retain
  • pass
  • relinquish
  • cede
  • desert
  • render
  • surrender
  • transfer
  • provide
  • dispense
  • furnish
  • disperse
  • dispense
  • succeed
  • produce
  • releave
  • done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

I-libs-api-nominated Nominated for discussion during a libs-api team meeting. S-waiting-on-t-libs-api Status: Awaiting decision from T-libs-api T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants