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

Use Cow<'static, str> for VhostUserDaemon name field. #196

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

epilys
Copy link
Member

@epilys epilys commented Oct 7, 2023

Summary of the PR

Change the name's type String to Cow<'static, str>. This allows the
library user to prevent string allocation from static strings, which is
how most crates use it.

This is an API breaking change.

Requirements

Before submitting your PR, please make sure you addressed the following
requirements:

  • All commits in this PR are signed (with git commit -s), and the commit
    message has max 60 characters for the summary and max 75 characters for each
    description line.
  • All added/changed functionality has a corresponding unit/integration
    test.
  • All added/changed public-facing functionality has entries in the "Upcoming
    Release" section of CHANGELOG.md (if no such section exists, please create one).
  • Any newly added unsafe code is properly documented.

Change the name's type `String` to `Cow<'static, str>`. This allows the
library user to prevent string allocation from static strings, which is
how most crates use it.

This is an API breaking change.

Signed-off-by: Manos Pitsidianakis <[email protected]>
@epilys epilys force-pushed the trivial/use-cow-for-name branch from cd15176 to f70b7a3 Compare October 24, 2023 07:31
@epilys epilys marked this pull request as ready for review October 24, 2023 07:31
@@ -124,7 +125,7 @@ where
mut handler: BackendReqHandler<Mutex<VhostUserHandler<T>>>,
) -> Result<()> {
let handle = thread::Builder::new()
.name(self.name.clone())
.name(self.name.to_string())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm... This is the only use and requires ownership. So should we maybe just drop it from the daemon struct and make it part of the start_daemon function (as a String that can be moved through)?

Though, overall, I think this is a lot of code churn (for everyone using this) and additional complexity for very little gain.

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