Skip to content

Commit

Permalink
Replace use of unsafe with pin_project (#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth authored Jan 23, 2025
1 parent 949ac94 commit f778d29
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions insta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ once_cell = "1.20.2"
# Not yet supported in our MSRV of 1.60.0
# clap = { workspace=true, optional = true }
clap = { version = "4.1", features = ["derive", "env"], optional = true }
pin-project = "1"

[dev-dependencies]
rustc_version = "0.4.0"
Expand Down
5 changes: 3 additions & 2 deletions insta/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,14 +523,15 @@ impl Settings {
/// # }
/// ```
pub fn bind_async<F: Future<Output = T>, T>(&self, future: F) -> impl Future<Output = T> {
struct BindingFuture<F>(Arc<ActualSettings>, F);
#[pin_project::pin_project]
struct BindingFuture<F>(Arc<ActualSettings>, #[pin] F);

impl<F: Future> Future for BindingFuture<F> {
type Output = F::Output;

fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
let inner = self.0.clone();
let future = unsafe { self.map_unchecked_mut(|s| &mut s.1) };
let future = self.project().1;
CURRENT_SETTINGS.with(|x| {
let old = {
let mut current = x.borrow_mut();
Expand Down

0 comments on commit f778d29

Please sign in to comment.