Let’s compare the currently recommended style with the style being proposed. For single line statements, they’re both identical. I’m adding some code to the function body to make it more realistic.
Multi-line statement, current style:
fn very_long_function(&mut self, long_name: &LongType, longer_name: LongerType,
longest_name: LongerType) -> Vec<LongType> {
self.method_call(long_name);
for element in longest_name.iter() {
self.do_stuff(element);
}
longer_name.make_vec(self)
}
Multi-line statement, proposed style without indenting to the level of the first argument (because the brace on the next line acts as delimiter):
fn very_long_function(&mut self, long_name: &LongType, longer_name: LongerType,
longest_name: LongerType) -> Vec<LongType>
{
self.method_call(long_name);
for element in longest_name.iter() {
self.do_stuff(element);
}
longer_name.make_vec(self)
}
Complicated or long type parameter lists also need to be considered. The current guidelines recommend the following:
fn very_long_function<T: Color + Weight,
U: Direction>(
&mut self,
long_name: &T,
longer_name: LongerType,
longest_name: U)
-> Vec<T> {
self.method_call(long_name);
for element in longest_name.iter() {
self.do_stuff(element);
}
longer_name.make_vec(self)
}
Proposed style:
fn very_long_function<T: Color + Weight, U: Direction>(&mut self, long_name: &T,
longer_name: LongerType, longest_name: U) -> Vec<T>
{
self.method_call(long_name);
for element in longest_name.iter() {
self.do_stuff(element);
}
longer_name.make_vec(self)
}
The where clauses RFC is also relevant to this discussion. With where clauses, the code from above could be written as
fn very_long_function<T,U>(&mut self,
long_name: &T,
longer_name: LongerType,
longest_name: U)
-> Vec<T>
where T: Color + Weight,
U: Direction {
self.method_call(long_name);
for element in longest_name.iter() {
self.do_stuff(element);
}
longer_name.make_vec(self)
}
I’m guessing here how where clauses would be indented. In the RFC, they are used like this:
fn very_long_function<T,U>(&mut self,
long_name: &T,
longer_name: LongerType,
longest_name: U)
-> Vec<T>
where T: Color + Weight,
U: Direction
{
...
}
In the proposed style, they could be used like this
fn very_long_function<T,U>(&mut self, long_name: &T, longer_name: LongerType,
longest_name: U) -> Vec<T>
where T: Color + Weight,
U: Direction
{
...
}
Obviously I prefer the proposed style, or at least my take on it.
PS: For some real examples, the Deque trait is written in the recommended style (and quite frankly, I find it dificult to read). Finally, looking at the std, indenting subsequent arguments to the level of the first argument is rare - evidently most users prefer a more traditional way to indent.