A rust proc-macro which allows for reading and writing to remote objects through a generated enum

Overview

Remote-Obj

A rust proc-macro which allows for reading and writing fields/variants of (possibly nested) remote objects by generating a single enum which covers all field reads and writes.

Intended for reading/writing config fields in embedded systems lazily, where bandwidth might be limited (and hence reading/writing the whole struct using something like serde is not desirable).

#[derive(RemoteSetter, RemoteGetter)]
struct SomeStruct {
    // ...
}

fn main() {
    let x = SomeStruct::new();

    // setter is a regular enum, and is the same type for any field
    let setter: <SomeStruct as Setter>::SetterType = set!(SomeStruct.field_name = expression);

    // can easily send setter over the wire/serialize it
    x.set(setter).unwrap();

    // works similarly with getters, the getter is the same type for any field
    let getter: <SomeStruct as Getter>::GetterType = get!(SomeStruct.field_name);

    // value is the same type for any field
    let value: <SomeStruct as Getter>::ValueType = x.get(getter).unwrap();

    // inner value actually returns the real value of the field
    let inner_value = value.field_name();
}

Dehydration

Also supports a more efficient method for transferring ValueTypes if both sides can agree on the interpretation (such as if the metadata is transferred beforehand, or if there is some sort of static mapping (such as CAN ids)).

let getter: <SomeStruct as Getter>::GetterType = get!(SomeStruct.field_name);
let value: <SomeStruct as Getter>::ValueType = x.get(getter).unwrap();

// here we take the ValueType and convert it to some raw bytes in a buffer
let length = value.dehydrate(&mut buf).unwrap();

// send the buffer over the wire

// on the other side, using the GetterType, we can hydrate the value from the buffer
let (rehydrated_v, same_length) = <SomeStruct as Getter>::hydrate(getter, &buf).unwrap();

assert_eq!(value, rehydrated_v);
assert_eq!(length, same_length);

Examples

See tests/test_derive.rs

You might also like...
Objective-C Runtime bindings and wrapper for Rust.

Objective-C Runtime bindings and wrapper for Rust. Documentation: http://ssheldon.github.io/rust-objc/objc/ Crate: https://crates.io/crates/objc Messa

“The Tie Between Ruby and Rust.”

Rutie Rutie — /ro͞oˈˌtī/rOOˈˌtI/rüˈˌtaI/ Integrate Ruby with your Rust application. Or integrate Rust with your Ruby application. This project allows

A minimalist and safe ECS library for rust!
A minimalist and safe ECS library for rust!

The full ECS (Entity-Component-System) library. Support an Open Source Developer! ♥️ Composed of two smaller libraries: world_dispatcher: the System p

A notebook app integrated with todo lists utility. Developed with Rust, WebAssembly, Yew and Trunk.

Flow.er A notebook app integrated with todo-list utility. Project flow.er is a Rust WASM app running in browser. Taking advantage of Yew and Trunk, it

A JavaScript Runtime built with Mozilla's SpiderMonkey Engine and Rust

Spiderfire Spiderfire is a javascript runtime built with Mozilla's SpiderMonkey engine and Rust. Spiderfire aims to disrupt the server-side javascript

A rust library containing typings and utility functions dealing with the Public specification of the Internet Computer.

IC Types Contributing Please follow the guidelines in the CONTRIBUTING.md document. Goal This library contains typings and utility functions dealing w

Modern JavaScript runtime for Sony PSP, based on rust-psp and QuickJS.

PSP.js Modern JavaScript runtime for Sony PSP, based on rust-psp and QuickJS. ⚠️ Currently in PoC state, unusable for developing JavaScript apps yet.

Implementation of the Radon and Inverse Radon Transforms in Rust

Radon Transform A rust and python implementation of the discretized version of the radon transform that I did out of boredom. The main mathematical tr

🚀 Fast and 100% API compatible postcss replacer, built in Rust

postcss-rs 🚀 Fast and 100% API compatible postcss replacer, built in Rust ⚠️ DO NOT USE. STILL WORK IN PROGRESS. Performance Improvement Tokenize boo

Owner
Ben Wang
Ben Wang
Simulation tools for animating interacting soft objects

Softy Simulation tools and libraries for animating rigid and soft objects (including cloth) subject to frictional contacts against smooth implicit sur

Egor Larionov 23 Jul 7, 2022
Rust bindings for writing safe and fast native Node.js modules.

Rust bindings for writing safe and fast native Node.js modules. Getting started Once you have the platform dependencies installed, getting started is

The Neon Project 7k Jan 4, 2023
Handy macro to generate C-FFI bindings to Rust for Haskell

hs-bindgen Handy macro to generate C-FFI bindings to Rust for Haskell. This library intended to work best in a project configured by cargo-cabal. N.B.

Yvan Sraka 32 Feb 16, 2023
A macro to generate constructor to instanicate structs from JsValue using duck-typing.

ducktor ducktor is a Rust crate that allows you to create types from wasm_bindgen::JsValue using duck typing. With ducktor, you can define a struct th

Muhammad Hamza 6 Jun 23, 2023
Robust and Fast tokenizations alignment library for Rust and Python

Robust and Fast tokenizations alignment library for Rust and Python Demo: demo Rust document: docs.rs Blog post: How to calculate the alignment betwee

Explosion 157 Dec 28, 2022
Rust Attribute-Based Encryption library rabe's C FFI binding , support CP-ABE and KP-ABE encrypt and decrypt, submodule of Rabe.Core c# library.

Rabe-ffi Rust Attribute-Based Encryption library rabe's C FFI binding , support CP-ABE and KP-ABE encrypt and decrypt, submodule of Rabe.Core c# libra

Aya0wind 2 Oct 10, 2022
Slitter is a C- and Rust-callable slab allocator implemented primarily in Rust, with some C for performance or to avoid unstable Rust features.

Slitter is a less footgunny slab allocator Slitter is a classically structured thread-caching slab allocator that's meant to help write reliable long-

Backtrace Labs 133 Dec 5, 2022
Automatically generates Rust FFI bindings to C (and some C++) libraries.

bindgen bindgen automatically generates Rust FFI bindings to C (and some C++) libraries. For example, given the C header doggo.h: typedef struct Doggo

The Rust Programming Language 3.2k Jan 4, 2023
Safe interop between Rust and C++

CXX — safe FFI between Rust and C++ This library provides a safe mechanism for calling C++ code from Rust and Rust code from C++, not subject to the m

David Tolnay 4.4k Jan 7, 2023
Bridge the gap between Haskell and Rust

Curryrs Curryrs (a play on the name of Haskell Curry, rs for Rust libraries, and it's pronunciation couriers) is a library for providing easy to use b

Michael Gattozzi 296 Oct 18, 2022