Skip to content

Commit b932b9d

Browse files
csnoverjam1garner
authored andcommitted
Switch to monorepo with workspaces
Tests and documentation that are out-of-sync due to a split repo make life unreasonably difficult when it can all just be in the same repo.
1 parent 4a65d52 commit b932b9d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2452
-22
lines changed

Cargo.toml

+5-22
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
1-
[package]
2-
name = "binread"
3-
version = "1.4.1"
4-
authors = ["jam1garner <[email protected]>"]
5-
edition = "2018"
6-
repository = "https://github.com/jam1garner/binread"
7-
license = "MIT"
8-
description = "A Rust crate for helping read structs from binary data using ✨macro magic✨"
9-
readme = "README.md"
10-
documentation = "https://docs.rs/binread"
11-
12-
[dependencies]
13-
binread_derive = { version = "1.4", path = "../binread_derive" }
14-
lazy_static = { version = "1.4" , optional=true }
15-
16-
[dev-dependencies]
17-
modular-bitfield = "0.9"
18-
19-
[features]
20-
default = ["std"]
21-
std = []
22-
debug_template = ["std", "lazy_static", "binread_derive/debug_template"]
1+
[workspace]
2+
members = [
3+
"binread",
4+
"binread_derive"
5+
]

binread/Cargo.toml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "binread"
3+
version = "1.4.1"
4+
authors = ["jam1garner <[email protected]>"]
5+
edition = "2018"
6+
repository = "https://github.com/jam1garner/binread"
7+
license = "MIT"
8+
description = "A Rust crate for helping read structs from binary data using ✨macro magic✨"
9+
readme = "README.md"
10+
documentation = "https://docs.rs/binread"
11+
12+
[dependencies]
13+
binread_derive = { version = "1.4", path = "../binread_derive" }
14+
lazy_static = { version = "1.4" , optional=true }
15+
16+
[dev-dependencies]
17+
modular-bitfield = "0.9"
18+
19+
[features]
20+
default = ["std"]
21+
std = []
22+
debug_template = ["std", "lazy_static", "binread_derive/debug_template"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

binread_derive/Cargo.toml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "binread_derive"
3+
version = "1.4.3"
4+
authors = ["jam1garner <[email protected]>"]
5+
edition = "2018"
6+
description = "Derive macro for binread"
7+
repository = "https://github.com/jam1garner/binread"
8+
license = "MIT"
9+
10+
[lib]
11+
proc-macro = true
12+
13+
[dependencies]
14+
syn = { version = "1", features = ["extra-traits", "full"] }
15+
quote = "1"
16+
proc-macro2 = "1"
17+
18+
[features]
19+
debug_template = []

binread_derive/src/binread_endian.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// An enum to represent the endianess to read
2+
#[derive(Clone, Copy, Debug, PartialEq)]
3+
pub enum Endian {
4+
Big,
5+
Little,
6+
Native,
7+
}
8+
9+
impl Into<String> for &Endian {
10+
fn into(self) -> String {
11+
String::from(
12+
match self {
13+
Endian::Big => "Big",
14+
Endian::Little => "Little",
15+
Endian::Native => "Native",
16+
}
17+
)
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use proc_macro2::TokenStream;
2+
use super::TopLevelAttrs;
3+
use crate::CompileError;
4+
use syn::DeriveInput;
5+
use quote::quote;
6+
7+
pub fn generate(_: &DeriveInput, _: &TopLevelAttrs) -> Result<TokenStream, CompileError> {
8+
Ok(quote!{Ok(())})
9+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use proc_macro2::TokenStream;
2+
use super::TopLevelAttrs;
3+
use crate::CompileError;
4+
5+
/// Generate the argument type for the derived impl
6+
pub fn generate(tla: &TopLevelAttrs) -> Result<TokenStream, CompileError> {
7+
Ok(tla.import.types())
8+
}
9+

binread_derive/src/codegen/mod.rs

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
pub(crate) mod sanitization;
2+
mod read_options;
3+
mod after_parse;
4+
mod arg_type;
5+
6+
use proc_macro2::TokenStream;
7+
use crate::{
8+
meta_attrs::TopLevelAttrs,
9+
compiler_error::{CompileError, SpanError}
10+
};
11+
12+
pub fn generate(input: &syn::DeriveInput) -> Result<GeneratedCode, CompileError> {
13+
if let syn::Data::Union(ref union) = input.data {
14+
SpanError::err(union.union_token.span, "Unions not supported")?
15+
}
16+
17+
let tla = TopLevelAttrs::from_derive_input(input)?.finalize()?;
18+
19+
Ok(GeneratedCode {
20+
arg_type: arg_type::generate(&tla)?,
21+
read_opt_impl: read_options::generate(input, &tla)?,
22+
after_parse_impl: after_parse::generate(input, &tla)?,
23+
})
24+
}
25+
26+
pub struct GeneratedCode {
27+
pub read_opt_impl: TokenStream,
28+
pub after_parse_impl: TokenStream,
29+
pub arg_type: TokenStream
30+
}
31+
32+
impl GeneratedCode {
33+
pub fn new<T1, T2, T3>(read_opt_impl: T1, after_parse_impl: T2, arg_type: T3) -> Self
34+
where T1: Into<TokenStream>,
35+
T2: Into<TokenStream>,
36+
T3: Into<TokenStream>
37+
{
38+
Self {
39+
read_opt_impl: read_opt_impl.into(),
40+
after_parse_impl: after_parse_impl.into(),
41+
arg_type: arg_type.into()
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)