Skip to content

Commit

Permalink
feat: support an arbitrary amount of in/outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
FWuermse committed Aug 2, 2023
1 parent 938f35f commit 58681ec
Show file tree
Hide file tree
Showing 9 changed files with 354 additions and 18 deletions.
11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@
name = "flowrs"
version = "0.1.0"
edition = "2021"
authors = ["wuermseer.florian@gmail.com", "markus.friedrich@hm.edu"]
description = "A generic and Type-Safe WASM library for Flow-Based Programming."
repository = "https://github.com/flow-rs/flowrs"
license = "Apache-2.0"
license-file = "LICENSE"
readme = "README.md"
documentation = "https://docs.rs/flowrs"
keywords = ["flow", "fbp", "wasm"]
categories = ["data-structures", "wasm"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
flow-derive = { path = "flow-derive" }
flowrs_derive = { version = "0.1.0", path = "flowrs_derive" }
serde = { version = "1.0.166", features = ["derive", "rc"] }
serde_json = "1.0.100"
threadpool = "1.8.1"
Expand Down
13 changes: 0 additions & 13 deletions flow-derive/Cargo.toml

This file was deleted.

21 changes: 21 additions & 0 deletions flowrs_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "flowrs-derive"
version = "0.2.0"
edition = "2021"
authors = ["wuermseer.florian@gmail.com", "markus.friedrich@hm.edu"]
description = "A macro for connecting flowrs Nodes during runtime."
repository = "https://github.com/flow-rs/flowrs/tree/master/flow_derive"
license = "Apache-2.0"
readme = "README.md"
documentation = "https://docs.rs/flowrs_derive"
keywords = ["flow", "fbp", "wasm"]
categories = ["data-structures", "wasm"]

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

[dependencies]
quote = "1.0.29"
syn = { version = "2.0.28", features = ["full"] }

[lib]
proc-macro = true
11 changes: 11 additions & 0 deletions flowrs_derive/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Executing Tests

All Rust internal test can be executed using:

```sh
$ cargo test
```

# Contributing

Please read our [Contribution Guidelines](https://github.com/flow-rs/flowrs/blob/master/CONTRIBUTING.md) first.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::panic;
use proc_macro::TokenStream;
use syn::{Arm, DataStruct, DeriveInput, Field, Type};
use syn::{Arm, DataStruct, DeriveInput, Field, Type, WherePredicate};

pub fn impl_connectable_trait(ast: DeriveInput) -> TokenStream {
let struct_ident = ast.clone().ident;
Expand Down Expand Up @@ -43,12 +43,12 @@ pub fn impl_connectable_trait(ast: DeriveInput) -> TokenStream {
})
.collect::<Vec<Arm>>();
let (_, ty_generics, _) = ast.generics.split_for_impl();
let mut generic_bounds = get_generic_bounds(inputs.clone());
generic_bounds.append(&mut get_generic_bounds(outputs));
quote::quote! {
impl #ty_generics RuntimeConnectable for #struct_ident #ty_generics
where
I1: Clone + 'static,
I2: Clone + 'static,
O: Clone + 'static,
#(#generic_bounds,)*
{
fn input_at(&self, index: usize) -> Rc<dyn Any> {
match index {
Expand All @@ -68,6 +68,33 @@ pub fn impl_connectable_trait(ast: DeriveInput) -> TokenStream {
.into()
}

fn get_generic_bounds(fields: Vec<Field>) -> Vec<WherePredicate> {
fields
.iter()
.map(|f| match &f.ty {
Type::Path(path) => match &path.path.segments.first().unwrap().arguments {
syn::PathArguments::AngleBracketed(angle) => match angle.args.first().unwrap() {
syn::GenericArgument::Type(generic) => match generic {
Type::Path(t_path) => {
let ident = t_path.path.segments.first().unwrap().ident.clone();
let cond: TokenStream = quote::quote! {
#ident: Clone + 'static
}
.into();
let cond_ast: WherePredicate = syn::parse(cond.clone()).unwrap();
cond_ast
}
_ => todo!(),
},
_ => todo!(),
},
_ => todo!(),
},
_ => todo!(),
})
.collect::<Vec<WherePredicate>>()
}

fn validate_struct_field(strct: DataStruct, ty: &str, mcro: &str) -> Vec<Field> {
strct
.fields
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod nodes;
1 change: 1 addition & 0 deletions tests/nodes/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod node;
Loading

0 comments on commit 58681ec

Please sign in to comment.