Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose OpaqueIpcMessage as IpcMessage #362

Merged
merged 1 commit into from
Oct 13, 2024
Merged

Conversation

mrobinson
Copy link
Member

This makes the API a bit friendlier and future-proof. Instead of
returning a tuple from raw recv() return the IpcMessage struct that
is used internally in the crate. In addition, this is used to pass data
from the platform layer -- removing clippy warnings about complex data
types. One upside to this is that Option<IpcSharedMemory> is turned
into IpcSharedMemory in some places where having a None value
shouldn't be possible.

This simplification removes about 300 lines of code.

@mrobinson
Copy link
Member Author

This will need #364 to work properly.

Copy link
Member

@jdm jdm left a comment

Choose a reason for hiding this comment

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

This is a really nice reduction in complexity!

Cargo.toml Outdated
@@ -20,6 +20,7 @@ name = "ipc_receiver_set"
harness = false

[features]
default = ["async"]
Copy link
Member

Choose a reason for hiding this comment

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

Why this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops, this was left over from local testing. I've removed it.

src/ipc.rs Outdated
Comment on lines 735 to 737
let _ = mem::replace(
&mut *os_ipc_shared_memory_regions_for_deserialization.borrow_mut(),
&mut self.os_ipc_shared_memory_regions,
old_ipc_shared_memory_regions_for_deserialization,
Copy link
Member

Choose a reason for hiding this comment

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

I think this would be equivalent to (and more clear as):

*os_ipc_shared_memory_regions_for_deserialization.borrow_mut() = old_ipc_shared_memory_regions_for_deserialization;

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@mrobinson mrobinson force-pushed the make-recv-friendlier branch from a8017a1 to 14c4add Compare October 13, 2024 07:14
This makes the API a bit friendlier and future-proof. Instead of
returning a tuple from raw `recv()` return the `IpcMessage` struct that
is used internally in the crate. In addition, this is used to pass data
from the platform layer -- removing clippy warnings about complex data
types. One upside to this is that `Option<IpcSharedMemory>` is turned
into `IpcSharedMemory` in some places where having a `None` value
shouldn't be possible.

This simplification removes about 300 lines of code.
@mrobinson mrobinson force-pushed the make-recv-friendlier branch from 14c4add to 1f231e4 Compare October 13, 2024 07:20
@mrobinson
Copy link
Member Author

Thanks for the review!

@mrobinson mrobinson added this pull request to the merge queue Oct 13, 2024
Merged via the queue into main with commit a29f223 Oct 13, 2024
17 checks passed
impl OpaqueIpcMessage {
fn new(
impl IpcMessage {
pub(crate) fn new(
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious if there is reason for not marking this as pub. The struct only has pub fields, so it doesn't seem like we are gaining much in terms of encapsulation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair enough. I think mainly this wasn't marked as pub because it isn't expected that a user of ipc-channel would ever need to create this data structure. pub(crate) is useful in this case because the compiler can determine if the function ever becomes unused.

Copy link
Member

Choose a reason for hiding this comment

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

because it isn't expected that a user of ipc-channel would ever need to create this data structure

Should we then remove the 'pub' from the fields? Having them public means it will become part of our API in the next release and OpaqueIpcMessage only had private fields. I'm happy to do the change.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not opposed to making the fields private again.

@mrobinson mrobinson deleted the make-recv-friendlier branch October 14, 2024 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants