Idea: Multi-line pub mod

To keep in line with use statements, would a multi-line pub mod be a good idea?

pub mod {
   bread,
   lettuce,
   bacon, 
   tomato, 
};
1 Like

It could be, but I think the normal way is simpler:

pub mod bread;  
pub mod lettuce;  
pub mod bacon;  
pub mod tomato;  

I think this is too complex:

pub mod {  
   bread,  
   lettuce,  
   bacon,  
   tomato,  
};  

I don't think it's that intuitive, but it could be useful for avoiding multiple pub mod statements.

So is:

use x;
use y;
use j;

A more idiomatic and simpler way than:

use {x, y, j};

?

It's mainly my own opinion, as I find curly braces a bit hard to write.
But I'd rather write multiple use statements than one with curly braces. For example, this import is complex in my own opinion:

pub use widget::{
    view::{View, WidgetType, WidgetValue, Event},
    button::Button,
    checkbox::Checkbox,
    label::Label,
    slider::Slider,
};

I only use this when I find multiple lines a bit chaotic.

Language change should be discussed at https://internals.rust-lang.org/. There you also have a greater chance that people interested in such things will see your idea.

(Personally, I'm not a fond of this change).

2 Likes

Thank you I will move there.

The difference is that use can contain long paths:

use std::collections::hash_map::{Entry, HashSet}

and repeating long paths is more noisy and tedious.

mod always takes only name.

mod creates a new item, so the name it mentions is closer to fn name or struct Name, rather than use path.

9 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.