Skip to content

Conversation

@kristof-mattei
Copy link
Contributor

@kristof-mattei kristof-mattei commented Jan 17, 2026

  • fix: allow to run tests locally against modified version of netlink-sys
  • fix: none of these methods modify the socket, they merely modify the kernel's state and the buffer's state
  • fix: none of these methods modify the socket, they merely modify the kernel's state

@gemini-code-assist
Copy link

Summary of Changes

Hello @kristof-mattei, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on enhancing the netlink-sys crate's API by refining its use of mutable references. The core change involves transitioning methods that do not inherently modify the socket's internal state (such as those interacting with the kernel or handling asynchronous I/O) from taking mutable references (&mut self) to immutable ones (&self). This improves the API's correctness and clarity, making it safer and easier to reason about the state of socket objects. Additionally, a configuration update has been included to facilitate local development and testing.

Highlights

  • API Refinement: Immutable References: Refactored numerous methods across the AsyncSocket trait, its extension AsyncSocketExt, and concrete implementations (SmolSocket, TokioSocket), as well as core Socket configuration methods, to use immutable references (&self) instead of mutable ones (&mut self). This change clarifies that these operations interact with the kernel's state or manage asynchronous polling without directly modifying the Rust socket object itself.
  • Examples and Tests Alignment: Updated example code for async_std and tokio, along with a test case in src/socket.rs, to remove unnecessary mut keywords from socket instance declarations, aligning with the new immutable reference pattern.
  • Local Development Support: Added a [patch.crates-io] entry in Cargo.toml to allow for local testing against a modified version of the netlink-sys crate, streamlining development workflows.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly removes unnecessary mutable borrows (&mut self) across the crate, replacing them with immutable borrows (&self). This is a good refactoring that improves the API ergonomics, especially for async code. The changes are consistent and well-justified by the fact that the modified methods only change kernel state or buffers, not the socket struct itself. The changes in src/socket.rs, src/async_socket.rs, src/async_socket_ext.rs, and the async backend implementations in src/smol.rs and src/tokio.rs are all correct. As a follow-up, you might consider removing the socket_mut() method from the AsyncSocket trait and its implementations, as it appears to be unused after these changes. Note that this would be a breaking change. I have one suggestion regarding the Cargo.toml file.

@kristof-mattei kristof-mattei changed the title no mut Replace &mut with & where we're not modifying the struct's state. Jan 17, 2026
@kristof-mattei kristof-mattei marked this pull request as ready for review January 18, 2026 02:52
Copy link
Member

@cathay4t cathay4t left a comment

Choose a reason for hiding this comment

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

Nice patch!

@cathay4t cathay4t merged commit f54c420 into rust-netlink:main Jan 22, 2026
3 checks passed
@kristof-mattei kristof-mattei deleted the no-mut branch January 22, 2026 15:53
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.

2 participants