Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for no_std compilation (updated) #177

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ jobs:
run: cargo test --verbose --all-features --all
- name: Build Examples
run: cargo build --examples --all-features --all
no_std_build:
name: no_std Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: rustup update
- name: Build
run: cargo build --verbose --no-default-features
- name: Build
run: cargo build --verbose --no-default-features --features=alloc
- name: Run tests
run: cargo test --verbose --no-default-features
- name: Run tests as no_std with alloc
run: cargo test --verbose --no-default-features --features=alloc
clippy:
name: Clippy
runs-on: ubuntu-latest
Expand Down
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ rust-version = "1.63.0"
derive_arbitrary = { version = "1.3.2", path = "./derive", optional = true }

[features]
# Provide support for std types by default.
default = ["std"]
# Turn this feature on to enable support for `#[derive(Arbitrary)]`.
derive = ["derive_arbitrary"]
# Whether or not to require the standard library. Turning off this feature
# makes Arbitrary work with no_std crates.
std = ["alloc"]
# Provide support for alloc types.
alloc = []

[[example]]
name = "derive_enum"
Expand Down
7 changes: 4 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{error, fmt};
use core::fmt;

/// An enumeration of buffer creation errors
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -32,12 +32,13 @@ impl fmt::Display for Error {
}
}

impl error::Error for Error {}
#[cfg(feature = "std")]
impl std::error::Error for Error {}

/// A `Result` with the error type fixed as `arbitrary::Error`.
///
/// Either an `Ok(T)` or `Err(arbitrary::Error)`.
pub type Result<T, E = Error> = std::result::Result<T, E>;
pub type Result<T, E = Error> = core::result::Result<T, E>;

#[cfg(test)]
mod tests {
Expand Down
Loading
Loading