Skip to content

Rust::com Field and Method Rust Design and Example of APIs usage - #818

Open
bharatGoswami8 wants to merge 28 commits into
eclipse-score:mainfrom
bharatGoswami8:Rust_Field_and_Method_APIs
Open

bharatGoswami8 wants to merge 28 commits into
eclipse-score:mainfrom
bharatGoswami8:Rust_Field_and_Method_APIs

Conversation

@bharatGoswami8

Copy link
Copy Markdown
Contributor

For Method and Field Design following things added -

  • Field subscribe/receive (FieldSubscriber, FieldSubscription traits): a consumer can subscribe to a field, receive value updates.

  • Field publish/update (FieldPublisher trait): a producer can update() a field value, register a set handler (called when a consumer sets the field), and register a get handler.

  • Field get/set on the consumer side reuse Method infrastructure: get_{name}() / set_{name}() async helpers are generated by the interface! macro using MethodCaller there is no separate field-get/set trait.

  • Method traits (MethodHandler for producer, MethodCaller for consumer): supports up to 8 arguments via tuple-based arities, with both copy and zero-copy call paths.

  • Type-state derive macro (#[derive(TypeStateValidator)]): generates compile-time state transitions so a producer struct cannot call offer() before all fields are initialized and all handlers are registered.

  • Interface macros split into producer and consumer: interface_producer_macros.rs generates the skeleton struct with all fields/methods/events; interface_consumer_macros.rs generates the proxy struct.

  • Runtime stub added to build the APIs example usage.

  • Example app with field_producer.rs, field_consumer.rs, method_producer.rs, method_consumer.rs modules showing the API usage end-to-end.

  • Design documents and diagrams for both Field and Method architecture added.

#579

Comment thread score/mw/com/example/com-api-example/src/field_producer.rs
Comment thread score/mw/com/example/com-api-example/src/method_producer.rs Outdated
Comment thread score/mw/com/example/com-api-example/src/field_producer.rs Fixed
Comment thread score/mw/com/example/com-api-example/src/field_producer.rs Fixed
Comment thread score/mw/com/impl/rust/com-api/com-api-runtime-lola/method.rs Fixed
Comment thread score/mw/com/impl/rust/com-api/com-api-runtime-lola/method.rs Fixed
Comment thread score/mw/com/impl/rust/com-api/com-api-runtime-mock/runtime.rs Fixed
Comment thread score/mw/com/impl/rust/com-api/com-api-runtime-mock/runtime.rs Fixed
Comment thread score/mw/com/impl/rust/com-api/com-api-runtime-mock/runtime.rs Fixed
Comment thread score/mw/com/rust/score_com_concept/interface_macros.rs Fixed
Comment thread score/mw/com/rust/score_com_concept/method_concept.rs Fixed
@LittleHuba

Copy link
Copy Markdown
Contributor

Putting to draft since state is not ready for review.

Comment thread score/mw/com/rust/score_com_concept/interface_macros.rs Fixed
@bharatGoswami8
bharatGoswami8 force-pushed the Rust_Field_and_Method_APIs branch from b7ffe17 to 7e70cbc Compare August 30, 2026 09:44
@bharatGoswami8

Copy link
Copy Markdown
Contributor Author

Putting to draft since state is not ready for review.

Addressed all the clippy and design comment.

@bharatGoswami8
bharatGoswami8 marked this pull request as ready for review August 31, 2026 03:22
interface!(
interface VehicleMethods {
Id = "VehicleMethodsInterface",
update_tire_pressure(Tire) -> (),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Applies to all method declarations) For the sake of symmetry I would vote for a slightly different syntax:

Suggested change
update_tire_pressure(Tire) -> (),
update_tire_pressure: Method(Tire) -> (),

This resembles Fn bounds and should be familiar to Rust developers. In addition, this makes the declaration look similar to fields and events.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes agreed, updated macro signature for method.

Id = "VehicleMethodsInterface",
update_tire_pressure(Tire) -> (),
update_front_tires_pressure(Tire, Tire) -> (),
get_tire_pressure() -> Tire,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo the examples aren't that compelling as the method calls declared here are very close to similar methods from fields (update_... and get_...). It would be better if there were a method that are quite different (something like calculate_hash_for: Method(&[u8], hash_type: HashType) -> u32).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated example and macro configuration.

// Allocate return the tuple of uninitialized method argument slots,
// We need to store in tuple format, or user need to access using uninit1.0.write(...)
let (uninit1,) = consumer
.update_tire_pressure

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would that work? In line 69 it looks like a callable, but here it looks like an object. Mixing this is afaik only possible by implementing an unstable Fn trait. Or did you find another solution for that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not using the unstable Fn trait. update_front_tires_pressure is an object (struct field) we get from the consumer struct, and a method with the same name is generated in the consumer's impl block by our interface macro.
And the underlying invocation happens using static dispatch via generic trait bounds (MethodCallInput), compiler generates a separate concrete function per type combination and picks the right one for each call site while compiling, not dynamic (dyn) trait dispatch, as shown in the example.

// A "dispatch" trait
trait CallMethod<Ret> {
    fn dispatch(self) -> Ret;
}

// Impl for "copy path"
impl CallMethod<String> for i32 {
    fn dispatch(self) -> String {
        format!("copy path, value = {}", self)
    }
}

// Impl for "zero-copy path"
struct Ptr(i32);
impl CallMethod<String> for Ptr {
    fn dispatch(self) -> String {
        format!("zero-copy path, ptr value = {}", self.0)
    }
}

struct Caller;

struct Consumer {
    // field named the same as the method below
    my_method: Caller,
}

impl Consumer {
    // generic inherent method, same name as the field
    fn my_method<A>(&self, arg: A) -> String
    where
        A: CallMethod<String>,
    {
        arg.dispatch()
    }
}

* Created Method related interface traits
* Updated Interface macro
* created method related macro
* For generating type state pattern for method and field
* Validating offer API call
* Added impl block for method interface
* Added impl block for method interface traits
* Added method api usage in example app
* Updated concept crate documentation
* Updated interface macro document
* Update type state macro document
* Updated return value to MethodReturnSample
* Added design markdown file and diagrams
* Added MethodReturnSample for returning value at consumer side
* MethodInArgPtr trait added for argument type
* Created field interface APIs
* Updated SampleMut to use in field as well
* Lola Runtime placeholder implementaion for field producer and consumer
* Mock Runtime placeholder implementation
* Create proc macro for field init and set handler validation before offer call
* Updated example file with Field APIs usage
* Method and field both code generation added on macros
* Removed the separate set-get method and introduced field method using Method interface
* Added Getter, Setter, Notifier tag for field feature to enable
* Create separate file for Producer and Consumer interface macro
* Updated set and get APIs for registration
* Updated tags for field to generate the field specific methods
* Updated intefrca macro as well
* Created trait level document design
* document for field desing
* set method returns the value
* Method API take the value by reference
@bharatGoswami8
bharatGoswami8 force-pushed the Rust_Field_and_Method_APIs branch 2 times, most recently from c0869c2 to d787ca5 Compare September 13, 2026 10:09
* Interface Macro uodated
* Updated method example

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

4 participants