Skip to content

Commit

Permalink
Merge pull request #37 from sergey-v-galtsev/warn_if_the_guard_is_dro…
Browse files Browse the repository at this point in the history
…pped_immediately

Warn if the guard is not assigned to a variable and is dropped immedi…
  • Loading branch information
bluss committed May 1, 2022
2 parents 220fb9f + 496bc65 commit c6e9d49
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ where
///
/// The `Strategy` decides whether the scope guard's closure should run.
#[inline]
#[must_use]
pub fn with_strategy(v: T, dropfn: F) -> ScopeGuard<T, F, S> {
ScopeGuard {
value: ManuallyDrop::new(v),
Expand Down Expand Up @@ -370,6 +371,7 @@ where

/// Create a new `ScopeGuard` owning `v` and with deferred closure `dropfn`.
#[inline]
#[must_use]
pub fn guard<T, F>(v: T, dropfn: F) -> ScopeGuard<T, F, Always>
where
F: FnOnce(T),
Expand All @@ -382,6 +384,7 @@ where
/// Requires crate feature `use_std`.
#[cfg(feature = "use_std")]
#[inline]
#[must_use]
pub fn guard_on_success<T, F>(v: T, dropfn: F) -> ScopeGuard<T, F, OnSuccess>
where
F: FnOnce(T),
Expand Down Expand Up @@ -418,6 +421,7 @@ where
/// ```
#[cfg(feature = "use_std")]
#[inline]
#[must_use]
pub fn guard_on_unwind<T, F>(v: T, dropfn: F) -> ScopeGuard<T, F, OnUnwind>
where
F: FnOnce(T),
Expand Down

0 comments on commit c6e9d49

Please sign in to comment.