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 6115dd9..0000000 --- a/.travis.yml +++ /dev/null @@ -1,33 +0,0 @@ -language: rust - -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/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..3c8055e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,11 +5,22 @@ 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" + +[lib] +# Due to the semver-trick, doctests do not compile: +# error[E0465]: multiple rlib candidates for `nb` found +doctest = false 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/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 diff --git a/src/lib.rs b/src/lib.rs index 7f0d386..a1f534f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -355,53 +355,10 @@ //! ``` #![no_std] -#![deny(warnings)] +#![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*) @@ -429,47 +386,18 @@ 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 } - } -} - -/// 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 @@ -503,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, } - } + }; }