Skip to content

Commit

Permalink
feat: Add no_std support
Browse files Browse the repository at this point in the history
  • Loading branch information
ball-hayden committed Mar 21, 2023
1 parent c8f384f commit 560ea13
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,6 +29,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: check
args: ${{ matrix.features }}

test:
name: Test Suite
Expand Down
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions src/traits.rs
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -178,6 +182,7 @@ where
}
}

#[cfg(feature = "alloc")]
impl<T, I, E> Parse<I, E> for Vec<T>
where
I: Clone + PartialEq + InputSlice,
Expand Down Expand Up @@ -215,6 +220,7 @@ where

/// *Note: this implementation uses const generics and requires rust >= 1.51*
#[rustversion::since(1.51)]
#[cfg(feature = "alloc")]
impl<T, I, E, const N: usize> Parse<I, E> for [T; N]
where
I: Clone + PartialEq + InputSlice,
Expand Down

0 comments on commit 560ea13

Please sign in to comment.