1 unstable release

0.3.1 Oct 27, 2024

#765 in Rust patterns

Download history 90/week @ 2024-10-22 27/week @ 2024-10-29

117 downloads per month

MIT license

15KB
332 lines

TCP-Struct

Access structs over TCP with 2 lines of code

Features

  • default = ["async-tcp"]
  • async-tcp

How to register?

#[register_impl]
impl MyStruct {
    pub async fn function1(self, input: u16) -> String { ... }
    pub async fn function2(self, input: u32) -> String { ... }
}

#[derive(TCPShare)]
struct MyStruct {}

How to use(Server)?

MyStruct::default().start(8082, "struct-version").await;

How to use(Client)?

let data = MyStruct::read(8082, "struct-version").function1(0);

Info

  • struct-version needs to be the same on both sides
  • the #[register_impl] needs to be above the #[derive(TCPShare)]
  • {MyStruct}Reader & {MyStruct}Writer structs are generated and therefor shouldnt be used
  • {MyStruct} start(self, port, identifier) & read(port, identifier) are generated and therefor shouldnt be used

Issues

  • the #[register_impl] needs to be above the #[derive(TCPShare)]
  • across files?

Dependencies

~3–11MB
~115K SLoC