Skip to content

Commit

Permalink
Project skeleton: #[bitfield]
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Mar 29, 2019
1 parent afb7e17 commit 07c1e7f
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bitfield/Cargo.toml
@@ -0,0 +1,16 @@
[package]
name = "bitfield"
version = "0.0.0"
edition = "2018"
autotests = false
publish = false

[[test]]
name = "tests"
path = "tests/progress.rs"

[dev-dependencies]
workshop-test-runner = { path = "../test-runner" }

[dependencies]
bitfield-impl = { path = "impl" }
11 changes: 11 additions & 0 deletions bitfield/impl/Cargo.toml
@@ -0,0 +1,11 @@
[package]
name = "bitfield-impl"
version = "0.0.0"
edition = "2018"
publish = false

[lib]
proc-macro = true

[dependencies]
# TODO
11 changes: 11 additions & 0 deletions bitfield/impl/src/lib.rs
@@ -0,0 +1,11 @@
extern crate proc_macro;

use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn bitfield(args: TokenStream, input: TokenStream) -> TokenStream {
let _ = args;
let _ = input;

unimplemented!()
}
15 changes: 15 additions & 0 deletions bitfield/src/lib.rs
@@ -0,0 +1,15 @@
// Crates that have the "proc-macro" crate type are only allowed to export
// procedural macros. So we cannot have one crate that defines procedural macros
// alongside other types of public APIs like traits and structs.
//
// For this project we are going to need a #[bitfield] macro but also a trait
// and some structs. We solve this by defining the trait and structs in this
// crate, defining the attribute macro in a separate bitfield-impl crate, and
// then re-exporting the macro from this crate so that users only have one crate
// that they need to import.
//
// From the perspective of a user of this crate, they get all the necessary APIs
// (macro, trait, struct) through the one bitfield crate.
pub use bitfield_impl::bitfield;

// TODO other things
1 change: 1 addition & 0 deletions bitfield/tests/00-INCOMPLETE
@@ -0,0 +1 @@
This test suite needs more work and explanations...
11 changes: 11 additions & 0 deletions bitfield/tests/01-parse.rs
@@ -0,0 +1,11 @@
use bitfield::*;

#[bitfield]
pub struct MyFourBytes {
a: B1,
b: B3,
c: B4,
d: B24,
}

fn main() {}
5 changes: 5 additions & 0 deletions bitfield/tests/progress.rs
@@ -0,0 +1,5 @@
#[test]
fn tests() {
let t = workshop::TestCases::new();
//t.pass("tests/01-parse.rs");
}

0 comments on commit 07c1e7f

Please sign in to comment.