diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d05739f..b236694 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -12,6 +12,11 @@ jobs: - stable - 1.48.0 - nightly + + features: + - '' + - '--no-default-features' + - '--no-default-features --features "alloc"' steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 @@ -24,6 +29,7 @@ jobs: - uses: actions-rs/cargo@v1 with: command: check + args: ${{ matrix.features }} test: name: Test Suite diff --git a/Cargo.toml b/Cargo.toml index f714cd4..e968fb8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,10 +29,15 @@ include = [ members = ["nom-derive-impl"] [dependencies] -nom = { version = "7.0", default-features = false, features = ["std"] } +nom = { version = "7.0", default-features = false } nom-derive-impl = { version="=0.10.0", path="./nom-derive-impl" } rustversion = "1.0" [dev-dependencies] pretty_assertions = "0.7" trybuild = "1.0" + +[features] +alloc = ["nom/alloc"] +default = ["std"] +std = ["alloc", "nom/std"] diff --git a/src/lib.rs b/src/lib.rs index 6b3751d..feb054b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,6 +106,8 @@ //! //! [nom]: https://github.com/geal/nom +#![cfg_attr(not(any(test, feature = "std")), no_std)] + pub mod docs; mod helpers; mod traits; diff --git a/src/traits.rs b/src/traits.rs index 2e48d84..dfd2cdd 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -1,13 +1,17 @@ use nom::bytes::streaming::take; use nom::combinator::{complete, map_res, opt}; use nom::error::{Error, FromExternalError, ParseError}; -use nom::multi::{many0, many_m_n}; use nom::number::streaming::*; use nom::sequence::pair; use nom::*; -use std::convert::TryFrom; use std::ops::RangeFrom; +#[cfg(feature = "alloc")] +use std::convert::TryFrom; + +#[cfg(feature = "alloc")] +use nom::multi::{many0, many_m_n}; + pub use nom::{InputLength, Slice}; pub trait InputSlice: @@ -178,6 +182,7 @@ where } } +#[cfg(feature = "alloc")] impl Parse for Vec where I: Clone + PartialEq + InputSlice, @@ -215,6 +220,7 @@ where /// *Note: this implementation uses const generics and requires rust >= 1.51* #[rustversion::since(1.51)] +#[cfg(feature = "alloc")] impl Parse for [T; N] where I: Clone + PartialEq + InputSlice,