diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..a640f38c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,78 @@ +name: CI + +on: + pull_request: + branches: + - master + push: + branches: + - master + +env: + RUSTFLAGS: -Dwarnings + RUST_BACKTRACE: 1 + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install Rust + run: rustup update stable + - run: cargo test --all-features --workspace + - run: cargo build --all-features --all-targets --workspace + + no-std: + strategy: + matrix: + target: + # TODO: Currently, valuable cannot build with targets that do not have atomic CAS. + # We should port https://github.com/rust-lang/futures-rs/pull/2400. + # - thumbv6m-none-eabi + - thumbv7m-none-eabi + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - 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 --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 + + fmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install Rust + run: rustup update stable + - run: cargo fmt --all -- --check + + docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install Rust + run: rustup update nightly && rustup default nightly + - run: cargo doc --no-deps --all-features + env: + RUSTDOCFLAGS: -Dwarnings diff --git a/valuable/benches/structable.rs b/valuable/benches/structable.rs index 127eece5..2eb4be7b 100644 --- a/valuable/benches/structable.rs +++ b/valuable/benches/structable.rs @@ -24,15 +24,16 @@ static FIELDS: &[NamedField<'static>] = &[ impl Structable for HelloWorld { fn definition(&self) -> StructDef<'_> { - StructDef { - name: "HelloWorld", - static_fields: FIELDS, - is_dynamic: false, - } + StructDef::new("HelloWorld", Fields::NamedStatic(FIELDS), false) + } +} + +impl Valuable for HelloWorld { + fn as_value(&self) -> Value<'_> { + Value::Structable(self) } fn visit(&self, v: &mut dyn Visit) { - let definition = self.definition(); v.visit_named_fields(&NamedValues::new( FIELDS, &[ @@ -52,7 +53,10 @@ fn criterion_benchmark(c: &mut Criterion) { let hello_world = black_box(HelloWorld::default()); let structable = &hello_world as &dyn Structable; - let f = &structable.definition().static_fields()[5]; + let f = match structable.definition().fields() { + Fields::NamedStatic(fields) => &fields[5], + _ => unreachable!(), + }; struct Sum(usize, &'static NamedField<'static>);