From b9783e26fa118cb9ee8260938cf9019697d8211d Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Sat, 26 Oct 2024 17:08:06 +0100 Subject: [PATCH] Remove unsafe, add MSRV policy --- .github/workflows/rust.yml | 12 ++++++++++++ README.md | 7 +++++++ src/lib.rs | 8 +------- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index bd5d712..29f4c03 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -31,3 +31,15 @@ jobs: run: cargo build --features macro --verbose - name: Run tests run: cargo test --features macro --verbose + msrv: + name: MSRV + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install MSRV + uses: dtolnay/rust-toolchain@master + with: + toolchain: "1.69" + components: rustfmt, clippy + - name: Check MSRV compatibility + run: cargo check --verbose --all-features diff --git a/README.md b/README.md index 5fe1d8c..427a859 100644 --- a/README.md +++ b/README.md @@ -75,3 +75,10 @@ You can also use `#[pollster::test]` for tests. ## Comparison with `futures::executor::block_on` `pollster` does approximately the same thing as the `block_on` function from the `futures` crate. If you already have `futures` in your dependency tree, you might as well use it instead. `pollster` is primarily for applications that don't care to pull all of `futures` or another runtime like `tokio` into their dependency tree for the sake of evaluating simple futures. + +## Minimum Supported Rust Version (MSRV) Policy + +Current MSRV: `1.69.0` + +`pollster` has a policy of supporting compiler versions that are at least 18 months old. The crate *may* compile with +older compilers, but this is not guaranteed. diff --git a/src/lib.rs b/src/lib.rs index 5351501..3ef58fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -109,13 +109,7 @@ impl Wake for Signal { /// let result = pollster::block_on(my_fut); /// ``` pub fn block_on(fut: F) -> F::Output { - let mut fut = fut.into_future(); - - // Pin the future so that it can be polled. - // SAFETY: We shadow `fut` so that it cannot be used again. The future is now pinned to the stack and will not be - // moved until the end of this scope. This is, incidentally, exactly what the `pin_mut!` macro from `pin_utils` - // does. - let mut fut = unsafe { std::pin::Pin::new_unchecked(&mut fut) }; + let mut fut = core::pin::pin!(fut.into_future()); // Signal used to wake up the thread for polling as the future moves to completion. We need to use an `Arc` // because, although the lifetime of `fut` is limited to this function, the underlying IO abstraction might keep