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

[unstable option] fn_single_line #3358

Open
scampi opened this issue Feb 13, 2019 · 2 comments
Open

[unstable option] fn_single_line #3358

scampi opened this issue Feb 13, 2019 · 2 comments
Labels
unstable option tracking issue of an unstable option

Comments

@scampi
Copy link
Contributor

scampi commented Feb 13, 2019

Tracking issue for unstable option: fn_single_line

@scampi scampi added the unstable option tracking issue of an unstable option label Feb 13, 2019
@scampi scampi changed the title [unstable option] unstable option: fn_single_line [unstable option] fn_single_line Feb 18, 2019
@dhardy
Copy link

dhardy commented Jan 1, 2020

Can this option be a little more selective please?

E.g., in my opinion, this is fine:

@@ -43,8 +97,6 @@
 }
 impl<T> AsMut<[T]> for Array64<T> {
-    fn as_mut(&mut self) -> &mut [T] {
-        &mut self.0
-    }
+    fn as_mut(&mut self) -> &mut [T] { &mut self.0 }
 }
 impl<T> Clone for Array64<T>
 where T: Copy + Default

but this is not:

@@ -64,13 +67,9 @@ fn game_host_open<R: Rng>(car: u32, choice: u32, rng: &mut R) -> u32 {
 
 // Returns the door we switch to, given our current choice and
 // the open door. There will only be one valid door.
-fn switch_door(choice: u32, open: u32) -> u32 {
-    free_doors(&[choice, open])[0]
-}
+fn switch_door(choice: u32, open: u32) -> u32 { free_doors(&[choice, open])[0] }
 
-fn free_doors(blocked: &[u32]) -> Vec<u32> {
-    (0..3).filter(|x| !blocked.contains(x)).collect()
-}
+fn free_doors(blocked: &[u32]) -> Vec<u32> { (0..3).filter(|x| !blocked.contains(x)).collect() }
 
 fn main() {
     // The estimation will be more accurate with more simulations

The inline_attribute_width option uses a line length to determine whether to allow a single option. The same thing here (excluding line indent) may provide a good option.

@yhm-amber
Copy link

yhm-amber commented Dec 11, 2022

Can this option be a little more selective please?

E.g., in my opinion, this is fine:

@@ -43,8 +97,6 @@
 }
 impl<T> AsMut<[T]> for Array64<T> {
-    fn as_mut(&mut self) -> &mut [T] {
-        &mut self.0
-    }
+    fn as_mut(&mut self) -> &mut [T] { &mut self.0 }
 }
 impl<T> Clone for Array64<T>
 where T: Copy + Default

but this is not:

@@ -64,13 +67,9 @@ fn game_host_open<R: Rng>(car: u32, choice: u32, rng: &mut R) -> u32 {
 
 // Returns the door we switch to, given our current choice and
 // the open door. There will only be one valid door.
-fn switch_door(choice: u32, open: u32) -> u32 {
-    free_doors(&[choice, open])[0]
-}
+fn switch_door(choice: u32, open: u32) -> u32 { free_doors(&[choice, open])[0] }
 
-fn free_doors(blocked: &[u32]) -> Vec<u32> {
-    (0..3).filter(|x| !blocked.contains(x)).collect()
-}
+fn free_doors(blocked: &[u32]) -> Vec<u32> { (0..3).filter(|x| !blocked.contains(x)).collect() }
 
 fn main() {
     // The estimation will be more accurate with more simulations

The inline_attribute_width option uses a line length to determine whether to allow a single option. The same thing here (excluding line indent) may provide a good option.


How about this :

fn free_doors(blocked: &[u32]) -> Vec<u32> 
{ (0..3).filter(|x| !blocked.contains(x)).collect() }

when brace_style = "AlwaysNextLine" ?

Almost type on a line and value on next line ...

And I do think this is better :

fn free_doors(blocked: &[u32]) -> Vec<u32> 
{
    (0..3)
        .filter(|x| !blocked.contains(x))
        .collect()
}

even if there is a fn_single_line = true option. This option is valuable only when a define is short enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unstable option tracking issue of an unstable option
Projects
None yet
Development

No branches or pull requests

3 participants