Skip to content

Commit

Permalink
Remove unsafe, add MSRV policy
Browse files Browse the repository at this point in the history
  • Loading branch information
zesterer committed Oct 26, 2024
1 parent d58d154 commit b9783e2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 1 addition & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,7 @@ impl Wake for Signal {
/// let result = pollster::block_on(my_fut);
/// ```
pub fn block_on<F: IntoFuture>(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
Expand Down

0 comments on commit b9783e2

Please sign in to comment.