From c7d733eb1d1bab041e2f324428cb479cacc6fe58 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Fri, 3 Jul 2020 19:04:39 +0200 Subject: [PATCH 1/5] Remove deny warnings but enforce it on CI --- .travis.yml | 4 ++++ src/lib.rs | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6115dd9..fffede3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,9 @@ language: rust +env: + global: + - RUSTFLAGS="-D warnings" + matrix: include: - env: TARGET=x86_64-unknown-linux-gnu diff --git a/src/lib.rs b/src/lib.rs index 7f0d386..dab1dc8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -355,7 +355,6 @@ //! ``` #![no_std] -#![deny(warnings)] use core::fmt; From 7d2c22d54a5a825289a748790e00bfa4c222f3b5 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Tue, 7 Jul 2020 20:24:22 +0200 Subject: [PATCH 2/5] Prepare 0.1.3 release --- CHANGELOG.md | 12 ++++++-- Cargo.toml | 10 +++++-- README.md | 4 +++ src/lib.rs | 78 +++------------------------------------------------- 4 files changed, 25 insertions(+), 79 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81e2f57..23feb87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +## [v0.1.3] - 2020-07-07 + +This release of the 0.1 version exists for compatibility with 1.0.0. +There are no functional changes compared to 0.1.2. + ## [v0.1.2] - 2019-04-21 ### Added @@ -26,6 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). Initial release -[Unreleased]: https://github.com/japaric/nb/compare/v0.1.2...HEAD -[v0.1.2]: https://github.com/japaric/nb/compare/v0.1.1...v0.1.2 -[v0.1.1]: https://github.com/japaric/nb/compare/v0.1.0...v0.1.1 +[Unreleased]: https://github.com/rust-embedded/nb/compare/v0.1.3...HEAD +[v0.1.3]: https://github.com/rust-embedded/nb/compare/v0.1.2...v0.1.3 +[v0.1.2]: https://github.com/rust-embedded/nb/compare/v0.1.1...v0.1.2 +[v0.1.1]: https://github.com/rust-embedded/nb/compare/v0.1.0...v0.1.1 diff --git a/Cargo.toml b/Cargo.toml index 7f06838..755bb28 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,11 +5,17 @@ description = "Minimal non-blocking I/O layer" keywords = ["await", "futures", "IO"] license = "MIT OR Apache-2.0" name = "nb" -repository = "https://github.com/japaric/nb" -version = "0.1.2" +repository = "https://github.com/rust-embedded/nb" +homepage = "https://github.com/rust-embedded/nb" +documentation = "https://docs.rs/nb" +readme = "README.md" +version = "0.1.3" # remember to update html_root_url [features] unstable = [] +[dependencies] +nb = "1" + [dev-dependencies] futures = "0.1.17" diff --git a/README.md b/README.md index 2fda3fa..13ec08d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ > Minimal and reusable non-blocking I/O layer +This project is developed and maintained by the [HAL team][team]. + ## [Documentation](https://docs.rs/nb) ## License @@ -19,3 +21,5 @@ at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. + +[team]: https://github.com/rust-embedded/wg#the-hal-team diff --git a/src/lib.rs b/src/lib.rs index dab1dc8..3e739cc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -355,52 +355,10 @@ //! ``` #![no_std] +#![doc(html_root_url = "https://docs.rs/nb/0.1.3")] -use core::fmt; - -/// A non-blocking result -pub type Result = ::core::result::Result>; - -/// A non-blocking error -/// -/// The main use of this enum is to add a `WouldBlock` variant to an existing -/// error enum. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub enum Error { - /// A different kind of error - Other(E), - /// This operation requires blocking behavior to complete - WouldBlock, -} - -impl fmt::Debug for Error -where - E: fmt::Debug, -{ - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - Error::Other(ref e) => fmt::Debug::fmt(e, f), - Error::WouldBlock => f.write_str("WouldBlock"), - } - } -} - -impl Error { - /// Maps an `Error` to `Error` by applying a function to a contained - /// `Error::Other` value, leaving an `Error::WouldBlock` value untouched. - pub fn map(self, op: F) -> Error where F: FnOnce(E) -> T { - match self { - Error::Other(e) => Error::Other(op(e)), - Error::WouldBlock => Error::WouldBlock, - } - } -} - -impl From for Error { - fn from(error: E) -> Error { - Error::Other(error) - } -} +extern crate nb; +pub use nb::{block, Error, Result}; /// Await operation (*won't work until the language gains support for /// generators*) @@ -441,35 +399,7 @@ macro_rules! await { } } -/// Turns the non-blocking expression `$e` into a blocking operation. -/// -/// This is accomplished by continuously calling the expression `$e` until it no -/// longer returns `Error::WouldBlock` -/// -/// # Input -/// -/// An expression `$e` that evaluates to `nb::Result` -/// -/// # Output -/// -/// - `Ok(t)` if `$e` evaluates to `Ok(t)` -/// - `Err(e)` if `$e` evaluates to `Err(nb::Error::Other(e))` -#[macro_export] -macro_rules! block { - ($e:expr) => { - loop { - #[allow(unreachable_patterns)] - match $e { - Err($crate::Error::Other(e)) => { - #[allow(unreachable_code)] - break Err(e) - }, - Err($crate::Error::WouldBlock) => {}, - Ok(x) => break Ok(x), - } - } - } -} + /// Future adapter /// From e4a1f4bbeaa006cc7293e19f7e10ccb488fe623c Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Tue, 7 Jul 2020 22:53:49 +0200 Subject: [PATCH 3/5] Deactivate doctests --- Cargo.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 755bb28..3c8055e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,3 +19,8 @@ nb = "1" [dev-dependencies] futures = "0.1.17" + +[lib] +# Due to the semver-trick, doctests do not compile: +# error[E0465]: multiple rlib candidates for `nb` found +doctest = false From 03c87e1c23472aa7ec7f042bb924d549c7ab9425 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Tue, 7 Jul 2020 22:54:31 +0200 Subject: [PATCH 4/5] Use GHA, bors and add codeowners from master branch --- .github/CODEOWNERS | 1 + .github/bors.toml | 7 ++++++ .github/workflows/ci.yml | 47 +++++++++++++++++++++++++++++++++++ .github/workflows/clippy.yml | 24 ++++++++++++++++++ .github/workflows/rustfmt.yml | 23 +++++++++++++++++ .travis.yml | 37 --------------------------- ci/after_success.sh | 20 --------------- ci/install.sh | 7 ------ ci/script.sh | 10 -------- 9 files changed, 102 insertions(+), 74 deletions(-) create mode 100755 .github/CODEOWNERS create mode 100755 .github/bors.toml create mode 100755 .github/workflows/ci.yml create mode 100755 .github/workflows/clippy.yml create mode 100755 .github/workflows/rustfmt.yml delete mode 100644 .travis.yml delete mode 100644 ci/after_success.sh delete mode 100644 ci/install.sh delete mode 100644 ci/script.sh diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100755 index 0000000..fcca011 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @rust-embedded/hal diff --git a/.github/bors.toml b/.github/bors.toml new file mode 100755 index 0000000..6d27f5a --- /dev/null +++ b/.github/bors.toml @@ -0,0 +1,7 @@ +block_labels = ["needs-decision"] +delete_merged_branches = true +required_approvals = 1 +status = [ + "ci-linux (stable, x86_64-unknown-linux-gnu)", + "ci-linux (1.35.0, x86_64-unknown-linux-gnu)", +] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100755 index 0000000..5a8e9de --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,47 @@ +on: + push: + branches: [ staging, trying, master ] + pull_request: + +name: Continuous integration + +env: + RUSTFLAGS: '-D warnings' + +jobs: + ci-linux: + runs-on: ubuntu-latest + strategy: + matrix: + # All generated code should be running on stable now + rust: [stable] + + # The default target we're compiling on and for + TARGET: [x86_64-unknown-linux-gnu] + + include: + # Test MSRV + - rust: 1.35.0 + TARGET: x86_64-unknown-linux-gnu + + # Test nightly but don't fail + - rust: nightly + experimental: true + TARGET: x86_64-unknown-linux-gnu + + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + target: ${{ matrix.TARGET }} + override: true + - uses: actions-rs/cargo@v1 + with: + command: check + args: --target=${{ matrix.TARGET }} + - uses: actions-rs/cargo@v1 + with: + command: test + args: --target=${{ matrix.TARGET }} diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml new file mode 100755 index 0000000..d67f81a --- /dev/null +++ b/.github/workflows/clippy.yml @@ -0,0 +1,24 @@ +on: + push: + branches: [ staging, trying, master ] + pull_request: + +name: Clippy check + +env: + RUSTFLAGS: '-D warnings' + +jobs: + clippy_check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + components: clippy + - uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/rustfmt.yml b/.github/workflows/rustfmt.yml new file mode 100755 index 0000000..9a55c00 --- /dev/null +++ b/.github/workflows/rustfmt.yml @@ -0,0 +1,23 @@ +on: + push: + branches: [ staging, trying, master ] + pull_request: + +name: Code formatting check + +jobs: + fmt: + name: Rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + components: rustfmt + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index fffede3..0000000 --- a/.travis.yml +++ /dev/null @@ -1,37 +0,0 @@ -language: rust - -env: - global: - - RUSTFLAGS="-D warnings" - -matrix: - include: - - env: TARGET=x86_64-unknown-linux-gnu - rust: nightly - -before_install: set -e - -install: - - bash ci/install.sh - -script: - - bash ci/script.sh - -after_script: set +e - -after_success: - - bash ci/after_success.sh - -cache: cargo -before_cache: - # Travis can't cache files that are not readable by "others" - - chmod -R a+r $HOME/.cargo - -branches: - only: - - staging - - trying - -notifications: - email: - on_success: never diff --git a/ci/after_success.sh b/ci/after_success.sh deleted file mode 100644 index 8c4cf08..0000000 --- a/ci/after_success.sh +++ /dev/null @@ -1,20 +0,0 @@ -set -euxo pipefail - -main() { - cargo doc --target $TARGET - - mkdir ghp-import - - curl -Ls https://github.com/davisp/ghp-import/archive/master.tar.gz | \ - tar --strip-components 1 -C ghp-import -xz - - ./ghp-import/ghp_import.py target/$TARGET/doc - - set +x - git push -fq https://$GH_TOKEN@github.com/$TRAVIS_REPO_SLUG.git gh-pages && \ - echo OK -} - -if [ $TRAVIS_BRANCH = master ]; then - main -fi diff --git a/ci/install.sh b/ci/install.sh deleted file mode 100644 index 642d79a..0000000 --- a/ci/install.sh +++ /dev/null @@ -1,7 +0,0 @@ -set -euxo pipefail - -main() { - return -} - -main diff --git a/ci/script.sh b/ci/script.sh deleted file mode 100644 index ff6d7e9..0000000 --- a/ci/script.sh +++ /dev/null @@ -1,10 +0,0 @@ -set -euxo pipefail - -main() { - cargo check --target $TARGET - - cargo check --target $TARGET --features unstable - cargo test --target $TARGET --features unstable -} - -main From 25364842c9a9293f1db0328c3d4ca5792e9fa08a Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Tue, 7 Jul 2020 22:54:44 +0200 Subject: [PATCH 5/5] Code formatting --- src/lib.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3e739cc..a1f534f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -386,21 +386,20 @@ macro_rules! await { loop { #[allow(unreachable_patterns)] match $e { - Err($crate::Error::Other(e)) => { + Err($crate::Error::Other(e)) => + { #[allow(unreachable_code)] break Err(e) - }, - Err($crate::Error::WouldBlock) => {}, // yield (see below) + } + Err($crate::Error::WouldBlock) => {} // yield (see below) Ok(x) => break Ok(x), } yield } - } + }; } - - /// Future adapter /// /// This is a *try* operation from a `nb::Result` to a `futures::Poll` @@ -432,10 +431,8 @@ macro_rules! try_nb { ($e:expr) => { match $e { Err($crate::Error::Other(e)) => return Err(e), - Err($crate::Error::WouldBlock) => { - return Ok(::futures::Async::NotReady) - }, + Err($crate::Error::WouldBlock) => return Ok(::futures::Async::NotReady), Ok(x) => x, } - } + }; }