Skip to content

Commit 07c1e7f

Browse files
committed
Project skeleton: #[bitfield]
1 parent afb7e17 commit 07c1e7f

File tree

7 files changed

+70
-0
lines changed

7 files changed

+70
-0
lines changed

bitfield/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "bitfield"
3+
version = "0.0.0"
4+
edition = "2018"
5+
autotests = false
6+
publish = false
7+
8+
[[test]]
9+
name = "tests"
10+
path = "tests/progress.rs"
11+
12+
[dev-dependencies]
13+
workshop-test-runner = { path = "../test-runner" }
14+
15+
[dependencies]
16+
bitfield-impl = { path = "impl" }

bitfield/impl/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "bitfield-impl"
3+
version = "0.0.0"
4+
edition = "2018"
5+
publish = false
6+
7+
[lib]
8+
proc-macro = true
9+
10+
[dependencies]
11+
# TODO

bitfield/impl/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extern crate proc_macro;
2+
3+
use proc_macro::TokenStream;
4+
5+
#[proc_macro_attribute]
6+
pub fn bitfield(args: TokenStream, input: TokenStream) -> TokenStream {
7+
let _ = args;
8+
let _ = input;
9+
10+
unimplemented!()
11+
}

bitfield/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Crates that have the "proc-macro" crate type are only allowed to export
2+
// procedural macros. So we cannot have one crate that defines procedural macros
3+
// alongside other types of public APIs like traits and structs.
4+
//
5+
// For this project we are going to need a #[bitfield] macro but also a trait
6+
// and some structs. We solve this by defining the trait and structs in this
7+
// crate, defining the attribute macro in a separate bitfield-impl crate, and
8+
// then re-exporting the macro from this crate so that users only have one crate
9+
// that they need to import.
10+
//
11+
// From the perspective of a user of this crate, they get all the necessary APIs
12+
// (macro, trait, struct) through the one bitfield crate.
13+
pub use bitfield_impl::bitfield;
14+
15+
// TODO other things

bitfield/tests/00-INCOMPLETE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This test suite needs more work and explanations...

bitfield/tests/01-parse.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use bitfield::*;
2+
3+
#[bitfield]
4+
pub struct MyFourBytes {
5+
a: B1,
6+
b: B3,
7+
c: B4,
8+
d: B24,
9+
}
10+
11+
fn main() {}

bitfield/tests/progress.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[test]
2+
fn tests() {
3+
let t = workshop::TestCases::new();
4+
//t.pass("tests/01-parse.rs");
5+
}

0 commit comments

Comments
 (0)