Skip to content

Add Signal::as_str() to get representation as static string#1138

Merged
bors[bot] merged 1 commit intonix-rust:masterfrom
MikailBag:master
Oct 29, 2019
Merged

Add Signal::as_str() to get representation as static string#1138
bors[bot] merged 1 commit intonix-rust:masterfrom
MikailBag:master

Conversation

@MikailBag
Copy link
Copy Markdown
Contributor

Motivation

Currently string representation of signal can be obtained with AsRef impl.
But it has downside: returned string's lifetime is bound to lifetime of signal, so &str must be converted to String. This allocation is avoidable, because as_ref() only returns static strings. To fix this problem, my PR adds Signal::as_str() method, which returns static string.

Copy link
Copy Markdown
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

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

This looks good. Could you also please include a CHANGELOG entry, showing users how to switch from the old method to the new one?

Comment thread src/sys/signal.rs Outdated
@MikailBag
Copy link
Copy Markdown
Contributor Author

Do docs look OK now?

@asomers
Copy link
Copy Markdown
Member

asomers commented Oct 26, 2019

Yeah, looks good. Just wrap the comment to 80 columns and I'll merge.

@MikailBag
Copy link
Copy Markdown
Contributor Author

Done

@MikailBag
Copy link
Copy Markdown
Contributor Author

Note: I changed signature of as_str to take self by-value, because Signal is Copy

Copy link
Copy Markdown
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

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

Perfect! Just squash your commits and I'll merge them. I can't squash your commits for you because Nix uses the bors merge bot.

@MikailBag
Copy link
Copy Markdown
Contributor Author

Squashed.

Copy link
Copy Markdown
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

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

bors r+

bors bot added a commit that referenced this pull request Oct 29, 2019
1138: Add Signal::as_str() to get representation as static string r=asomers a=MikailBag

# Motivation
Currently string representation of signal can be obtained with AsRef<str> impl.
But it has downside: returned string's lifetime is bound to lifetime of signal, so &str must be converted to String. This allocation is avoidable, because as_ref() only returns static strings. To fix this problem, my PR adds Signal::as_str() method, which returns static string.

Co-authored-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
@bors
Copy link
Copy Markdown
Contributor

bors bot commented Oct 29, 2019

Build succeeded

@bors bors bot merged commit bacb85e into nix-rust:master Oct 29, 2019
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