Skip to content

Commit

Permalink
Fix build error when alloc feature is disabled (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e authored May 11, 2021
1 parent a91f832 commit eba3f71
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
30 changes: 13 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,24 @@ jobs:
- name: Install Rust
run: rustup update stable
- run: rustup target add ${{ matrix.target }}
# TODO: Currently, valuable cannot build without `alloc` feature
# because `Debug` impl of `dyn Enumerable` uses `format!` macro.
# - run: cargo build --target ${{ matrix.target }} --no-default-features
# working-directory: valuable
# - run: cargo build --target ${{ matrix.target }} --no-default-features --features derive
# working-directory: valuable
- run: cargo build --target ${{ matrix.target }} --no-default-features
working-directory: valuable
- run: cargo build --target ${{ matrix.target }} --no-default-features --features derive
working-directory: valuable
- run: cargo build --target ${{ matrix.target }} --no-default-features --features alloc
working-directory: valuable
- run: cargo build --target ${{ matrix.target }} --no-default-features --features alloc,derive
working-directory: valuable

# TODO: Currently, valuable cannot build without `alloc` feature
# because `Debug` impl of `dyn Enumerable` uses `format!` macro.
# features:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - name: Install Rust
# run: rustup update stable
# - name: Install cargo-hack
# run: cargo install cargo-hack
# - run: cargo hack build --workspace --feature-powerset --no-dev-deps
features:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup update stable
- name: Install cargo-hack
run: cargo install cargo-hack
- run: cargo hack build --workspace --feature-powerset

fmt:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace]

resolver = "2"
members = [
"valuable",
"valuable-derive",
"tests",
]
]
6 changes: 4 additions & 2 deletions valuable/src/enumerable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,11 @@ impl<'a> DynamicVariant<'a> {

impl fmt::Debug for dyn Enumerable + '_ {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let def = self.definition();
let variant = self.variant();
let name = format!("{}::{}", def.name(), variant.name());
#[cfg(feature = "alloc")]
let name = format!("{}::{}", self.definition().name(), variant.name());
#[cfg(not(feature = "alloc"))]
let name = variant.name();

if variant.is_named_fields() {
struct DebugEnum<'a, 'b> {
Expand Down
9 changes: 9 additions & 0 deletions valuable/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ use core::fmt;
macro_rules! slice {
(
$(
$(#[$attrs:meta])*
$variant:ident($ty:ty),
)*
) => {
#[non_exhaustive]
pub enum Slice<'a> {
$(
$(#[$attrs])*
$variant(&'a [$ty]),
)*
}
Expand All @@ -19,6 +21,7 @@ macro_rules! slice {

enum IterKind<'a> {
$(
$(#[$attrs])*
$variant(core::slice::Iter<'a, $ty>),
)*
}
Expand All @@ -27,6 +30,7 @@ macro_rules! slice {
pub fn len(&self) -> usize {
match self {
$(
$(#[$attrs])*
Slice::$variant(s) => s.len(),
)*
}
Expand All @@ -53,6 +57,7 @@ macro_rules! slice {
fn into_iter(self) -> Self::IntoIter {
Iter(match self {
$(
$(#[$attrs])*
Slice::$variant(s) => IterKind::$variant(s.iter()),
)*
})
Expand All @@ -67,6 +72,7 @@ macro_rules! slice {

match *self {
$(
$(#[$attrs])*
$variant(v) => d.entries(v),
)*
};
Expand All @@ -83,6 +89,7 @@ macro_rules! slice {

match &self.0 {
$(
$(#[$attrs])*
$variant(v) => v.size_hint(),
)*
}
Expand All @@ -93,6 +100,7 @@ macro_rules! slice {

match &mut self.0 {
$(
$(#[$attrs])*
$variant(v) => v.next().map(|v| {
Valuable::as_value(v)
}),
Expand All @@ -115,6 +123,7 @@ slice! {
I128(i128),
Isize(isize),
Str(&'a str),
#[cfg(feature = "alloc")]
String(alloc::string::String),
U8(u8),
U16(u16),
Expand Down

0 comments on commit eba3f71

Please sign in to comment.