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

code style improvements for src/rust/protover/ffi.rs #179

Merged

Conversation

Labels
None yet
Projects
None yet
5 participants
@frewsxcv
Copy link
Contributor

@frewsxcv frewsxcv commented Jun 26, 2018

https://trac.torproject.org/projects/tor/ticket/26492#comment:2

Copy link
Contributor

@tlyu tlyu left a comment

Thanks for the patches! Overall, these changes seem like helpful code style improvements. Which style guide (if any) did you refer to for these? Is it https://github.com/rust-lang-nursery/fmt-rfcs/blob/master/guide/guide.md ?

I would say these are more code style improvements rather than refactoring, because the content of functions hasn't really been rearranged to improve modularity.

I also made a few inline review comments.

if proto_entry.supports_protocol(&protocol, &version) {
1
} else {
0
Copy link
Contributor

@tlyu tlyu Jul 10, 2018

Why not proto_entry.supports_protocol(&protocol, &version) as i32? Or maybe that should be as c_int?

Copy link
Contributor

@tlyu tlyu Jul 10, 2018

Alternatively, maybe putting the if-else in a single line as in https://github.com/rust-lang-nursery/fmt-rfcs/blob/master/guide/expressions.md#single-line-if-else
might be good.

Copy link
Contributor Author

@frewsxcv frewsxcv Jul 10, 2018

Considering rustfmt didn't automatically put it on one line, I assume it's not considered "small", as per this from your link:

...it contains a single else clause, and is small.

Copy link
Contributor

@tlyu tlyu Jul 11, 2018

I think it's in expression context, because it ends up being the implicitly returned value, so the single line if-else is allowed. It's not part of a larger statement or expression on the same line though, so maybe it's in a gray area, especially given the counterexample later in that section. (There's not enough context to tell if the multiline if-else is the last expression of a larger block.)

@@ -9,9 +9,9 @@ use libc::c_void;

// Define a no-op implementation for testing Rust modules without linking to C
#[cfg(feature = "testing")]
pub fn allocate_and_copy_string(s: &String) -> *mut c_char {
pub fn allocate_and_copy_string(s: &str) -> *mut c_char {
Copy link
Contributor

@tlyu tlyu Jul 10, 2018

This seems like a good change, and seems to be more aligned with how a lot of idiomatic Rust code takes string parameters.

@frewsxcv
Copy link
Contributor Author

@frewsxcv frewsxcv commented Jul 10, 2018

Thanks for the patches! Overall, these changes seem like helpful code style improvements. Which style guide (if any) did you refer to for these? Is it https://github.com/rust-lang-nursery/fmt-rfcs/blob/master/guide/guide.md ?

Yep. The style changes were all made automatically via the rustfmt tool.

@chelseakomlo
Copy link
Contributor

@chelseakomlo chelseakomlo commented Jul 11, 2018

This PR looks good to me! Thanks for changing allocate_and_copy_string to take a str, this is a nice improvement.

@tlyu tlyu changed the title Refactoring src/rust/protover/ffi.rs. code style improvements for src/rust/protover/ffi.rs Jul 11, 2018
@tlyu
Copy link
Contributor

@tlyu tlyu commented Jul 11, 2018

@frewsxcv would you be willing to write a changes file? (see https://trac.torproject.org/projects/tor/ticket/26492#comment:9) We can also do this for you if you like because you've allowed maintainers to update your pull request branch. This PR might be in the gray area of things that need a changes file but it does (backwards-compatibly) change an interface.

@coveralls
Copy link

@coveralls coveralls commented Jul 13, 2018

Coverage Status

Coverage decreased (-0.4%) to 59.478% when pulling 7585523 on frewsxcv:frewsxcv-stringlist-refactor into b556894 on torproject:master.

@torproject-pusher torproject-pusher merged commit 7585523 into torproject:master Jul 13, 2018
1 check passed
@frewsxcv frewsxcv deleted the frewsxcv-stringlist-refactor branch Jul 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment