Skip to content

Rust::com Field APIs design and example of usage - #700

Closed
bharatGoswami8 wants to merge 5 commits into
eclipse-score:mainfrom
bharatGoswami8:Rust_Field_APIs_Desing_and_Example
Closed

Rust::com Field APIs design and example of usage#700
bharatGoswami8 wants to merge 5 commits into
eclipse-score:mainfrom
bharatGoswami8:Rust_Field_APIs_Desing_and_Example

Conversation

@bharatGoswami8

@bharatGoswami8 bharatGoswami8 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

edit -

Since the Field and Method changes are closely related, and the Field implementation also uses the Method interface while both share the same macro for the interface and type-state pattern, I believe it would be better to review the overall design in a single PR. This will help ensure that any suggestions or feedback can be addressed more effectively and consistently across both implementations.
Therefore, I am closing this PR. Please review the PR - #818


  • Added field-based publish/subscribe with field get/set and asynchronous field subscriptions.
  • Extended interface macros to support field members and generated producer/consumer and compile-time offer API enable.
  • Added a new example demonstrating offered field producers and consumer field updates.

#579

Comment thread score/mw/com/rust/score_com_concept/interface_macros.rs Outdated
@bharatGoswami8
bharatGoswami8 force-pushed the Rust_Field_APIs_Desing_and_Example branch 3 times, most recently from 6faaa6c to 21d958d Compare July 14, 2026 06:23
@bharatGoswami8
bharatGoswami8 force-pushed the Rust_Field_APIs_Desing_and_Example branch from 30e0af1 to 8589c65 Compare July 19, 2026 08:53
@anmittag anmittag moved this from Backlog to In Progress in COM - Communication FT Jul 21, 2026
Comment thread score/mw/com/example/com-api-example/basic-consumer-producer.rs Outdated
Comment thread score/mw/com/example/com-api-example/basic-consumer-producer.rs Outdated
Comment thread score/mw/com/example/com-api-example/basic-consumer-producer.rs Outdated

@darkwisebear darkwisebear left a comment

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.

I mainly reviewed the concept part; I think we need to nail that part before it makes sense to look at the rest.

Comment thread score/mw/com/example/com-api-example/basic-consumer-producer.rs Outdated
// Must register handlers and initialize all fields before offer() is available
let offered = producer
.init_field()
.register_set_handler_left_tire(move |val: &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.

I wonder whether &Tire is correct. Why not hand over ownership to the callable? This way, the implementer wouldn't have to clone the value in the likely case the value is written somewhere.

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 callable with Fn(T)

println!("Received exhaust update");
})
.expect("Failed to register set handlers")
.update_left_tire(&initial_tire_value)

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.

Why by-reference? This forces cloning as the implementation most likely has to clone the value to send it across the network. It might be a corner case, though.

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.

Agreed, i was trying to match with C++ semantic but this will add additional clone, will go with same approach of send for Event.

use std::fmt::Debug;
use std::future::Future;

#[allow(dead_code)]

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.

Why is this dead code?

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 app.

#[allow(dead_code)]
// Temp for build test
// We will remove this once memory layout of same created in rust side like SamplePtr.
#[repr(C)]

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.

Doesn't this trigger an "improper_ctypes" lint? Result isn't #[repr(C)], so it cannot be used here properly.

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.

This is temporary placeholder of MethodReturnTypePtr of C++ like SamplePtr for Event.

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.

Now we are using method interface to create Field's method (set and get), so this is removed.

// or by default we will enable for user,
// -> we can keep it default enable as of now,
// and later we can add tag based mechanism if required because Interface side we need to check how we can do this
// 2. We are offering get method after subscrption async but before subscription it is sync,

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.

Just turn the one before subscription into async. Or is there anything that prevents you from doing so?

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.

Now we are using method interface to create Field's method (set and get), so this is removed but
We have another issue consumer partially moved when we call subscribe on field because it take self by value.

// we will create a module which will have common trait for event and field which will be used by both event and field as a super trait and
// for this we need to create marker trait for event.

use crate::*;

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.

Please import specific types. Yes, it's tedious, but being explicit here also saves some headaches.

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.

Done

/// # Returns
/// Return the result of `Result<()>` which contains the status of the register operation.
// TODO: Do we need to make callback lifetime 'static or we keep same as field publisher lifetime.
fn register_set_handler<'a>(&self, callback: impl Fn(&T) + Send + 'a) -> Result<()>;

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.

There is no equivalent method for registering the get handler. It may sound weird, but the C++ counterpart has that, since mw::com treats set and get as ordinary methods.

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.

Added.

/// # Returns
/// Return the result of `Result<()>` which contains the status of the register operation.
// TODO: Do we need to make callback lifetime 'static or we keep same as field publisher lifetime.
fn register_set_handler<'a>(&self, callback: impl Fn(&T) + Send + 'a) -> Result<()>;

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.

TO me this feels as if we're treating ordinary methods and field methods in a distinct way. Maybe we should think about getting methods ready first and then incorporate them as the foundation of set and get here.

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.

Method Design is ready - #777
Working on Combined Field and Method changes.

@@ -329,18 +342,10 @@ where
///
/// # Type Parameters
/// * `T` - The relocatable event data type
pub trait SampleMut<T>: DerefMut<Target = T> + Debug
pub trait EventSampleMut<T>: SampleMut<T>

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.

Is this just because of update vs send (aka naming)?

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, because of that SampleMut is just marker trait and then we have feature specific trait which provide the API like send and update.

* 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
@bharatGoswami8
bharatGoswami8 force-pushed the Rust_Field_APIs_Desing_and_Example branch from 8589c65 to 3d76ef9 Compare July 29, 2026 08:31
* Method and field both code generation added on macros
@bharatGoswami8

Copy link
Copy Markdown
Contributor Author

@darkwisebear , I will create a separate PR based on the Method Design PR, and all review feedback will be addressed in that PR.

@bharatGoswami8

Copy link
Copy Markdown
Contributor Author

Hi @darkwisebear , @rpreddyhv ,

I have created PR #818 for field design based on Method design interface.

I already addressed most of the review comment on this PR.

Request for review mentioned PR.

Closing this PR.

@github-project-automation github-project-automation Bot moved this from In Progress to Done in COM - Communication FT Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants