Skip to content

Commit

Permalink
changing crate name
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorlott committed Feb 17, 2023
1 parent 6707ce7 commit 24c2ade
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 70 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
[package]
name = "rust-typed"
version = "0.1.1"
name = "dismantler"
version = "0.0.1"
edition = "2021"
description = "Get the types of a struct"
license = "MIT OR Apache-2.0"
keywords = ["rust", "type", "type-it", "typed", "protocol"]
keywords = ["type", "dismantle", "typed", "protocol", "dismantler"]
authors = ["Viktor Lott"]
categories = ["development-tools::procedural-macro-helpers"]
repository = "https://github.com/viktorlott/typed"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
proc-macro2 = "1.0.49"
Expand Down
93 changes: 58 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,62 @@
# rust-typed
# Dismantler

`Typed` is a procedural macro that is used for disassembling `structs` and `fns` into their inner `type` components that are then accompanied with documentation and examples. The `Typed` structures will be wrapped into a module and reassigned with a name (default `core`), this also goes for the `static` and `generic` fields.
[<img alt="github" src="https://img.shields.io/github/languages/code-size/viktorlott/typed?style=flat-square&logo=github" height="20">](https://github.com/viktorlott/typed)
[<img alt="crates.io" src="https://img.shields.io/crates/v/dismantler?style=flat-square&logo=rust" height="20">](https://crates.io/crates/dismantle)


#### *Project is still under development*
`Dismantler` is a procedural macro that is used for disassembling `structs` and `fns` into their inner `type` components that are then accompanied with documentation and examples. The `Dismantler` structures will be wrapped into a module and reassigned with a name (default `core`), this also goes for the `static` and `generic` fields.


#### **Project is still under development**

## Examples
```toml
[dependencies]
dismantler = "0.0.1"
```

```rust
use dismantler::dismantle;

#[dismantle]
struct Container<C: Clone, T = i64> {
a: i32,
b: Vec<i32>,
c: Vec<T>,
d: C,
e: T
}

#[dismantle]
struct Tuple(i32, i32);

#[dismantle]
struct Tuple2<T>(i32, T);

fn main() {
let a: Container::a = 10;
let b: Container::b = vec![a];
let c: Container::c<i64> = vec![10];
let c: <Container::core<i64> as Container::protocol>::c = c;
let d: <Container::core<i64> as Container::protocol>::d = 10;
let container: Container::core<i64> = Container::core { a, b, c, d, e: 10 };

assert!(container.a == a);
}
```

### More examples

# Struct example
```rust
#[type_it]
use dismantler::dismantle;

#[dismantle]
struct Containter<T> {
current: u8,
buffer: Vec<u8>,
another: T,
}
#[type_it]
#[dismantle]
struct Area(i32);
```
- Will let you access the struct types as followed:
Expand All @@ -35,38 +78,16 @@ trait Trait: Container::protocol {
fn extend(&mut self, val: Container::protocol::another);
}
```
### More
````rust
#[type_it]
struct Container<C: Clone, T = i64> {
a: i32,
b: Vec<i32>,
c: Vec<T>,
d: C,
e: T
}

#[type_it]
struct Tuple(i32, i32);

#[type_it]
struct Tuple2<T>(i32, T);

fn main() {
let a: Container::fields::a = 10;
let b: Container::b = vec![a];
let c: Container::c<i64> = vec![10];
let c: <Container::core<i64> as Container::protocol>::c = c;
let d: <Container::core<i64> as Container::protocol>::d = 10;
let container: Container::core<i64> = Container::core { a, b, c, d, e: 10 };
### Current support:
- [x] **Struct**`static` and `generic` types
- [ ] **Function**`static` and `generic` types

assert!(container.a == a);
}
````

# Disassembler
### Disassembler
```rust
#[type_it]
#[dismantle]
struct #name {
#(#ident: #ty)*
}
Expand All @@ -92,10 +113,12 @@ pub mod #name {
}
```

# Future plans
### Future plans
#### Renaming disassembler
```rust
#[type_it = "MContainer"]
use dismantler::dismantle;

#[dismantle = "MContainer"]
struct Containter<T> {
current: u8,
buffer: Vec<u8>,
Expand Down
6 changes: 4 additions & 2 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,16 @@ impl ToTokens for TypeModule {
impl ToTokens for TypeModuleInner {
fn to_tokens(&self, tokens: &mut TokenStream2) {
let type_decls: &Vec<TypeAlias> = &self.type_decls;
let field_decls = type_decls.iter().map(|t| t.ident.clone()).collect::<Vec<Ident>>();


let type_decls = quote!(#(#type_decls)*);
let struct_decl = &self.struct_decl;
let generic_decl = &self.generic_decl;

let inner_decls = quote!(
pub mod fields {
#type_decls
pub mod field {
#(pub struct #field_decls;)*
}

#type_decls
Expand Down
22 changes: 11 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
#![doc = include_str!("../README.md")]

use proc_macro::TokenStream;

mod tools;
mod builder;
mod tools;

/// Use `type_it` as a proc-macro.
/// Use `dismantle` as a proc-macro.
/// - *Every field should be documented so it's easier to know what is what.*
///
///
/// # Example
/// ```no_run
/// #[type_it]
/// #[dismantle]
/// struct Containter<T> {
/// current: u8,
/// buffer: Vec<u8>,
/// another: T,
/// }
/// #[type_it]
/// #[dismantle]
/// struct Area(i32);
/// ```
/// - Will let you access the struct types as followed:
/// ```no_run
/// let current: Container::current = 10;
/// let buffer: Container::buffer = vec![current];
/// let another: <Container::core<u8> as Container::protocol>::another = 20;
/// let container: Container::core<u8> =
/// let container: Container::core<u8> =
/// Container::core {
/// current,
/// buffer,
Expand All @@ -33,13 +35,11 @@ mod builder;
/// ```no_run
/// trait Trait: Container::protocol {
/// fn retrieve(&self) -> Container::protocol::buffer;
/// fn extend(&mut self, val: Container::protocol::another);
/// fn extend(&mut self, val: Container::protocol::another);
/// }
/// ```
///
///
#[proc_macro_attribute]
pub fn type_it(_attr: TokenStream, item: TokenStream) -> TokenStream {
pub fn dismantle(_attr: TokenStream, item: TokenStream) -> TokenStream {
builder::codegen(_attr, item)
}


15 changes: 9 additions & 6 deletions tests/typed-test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![allow(unused_variables)]

extern crate rust_typed;
use rust_typed::type_it;
extern crate dismantler;
use dismantler::dismantle;

#[type_it]
#[dismantle]
struct Container<C: Clone, T = i64> {
a: i32,
b: Vec<i32>,
Expand All @@ -12,19 +12,22 @@ struct Container<C: Clone, T = i64> {
e: T
}

#[type_it]
#[dismantle]
struct Tuple(i32, i32);

#[type_it]
#[dismantle]
struct Tuple2<T>(i32, T);

fn main() {
let a: Container::fields::a = 10;
let a: Container::a = 10;
let b: Container::b = vec![a];
let c: Container::c<i64> = vec![10];
let c: Container::c = c;
let c: <Container::core<i64> as Container::protocol>::c = c;
let d: <Container::core<i64> as Container::protocol>::d = 10;
let container: Container::core<i64> = Container::core { a, b, c, d, e: 10 };



assert!(container.a == a);
}

0 comments on commit 24c2ade

Please sign in to comment.