Safenet Client API module structure

Hello.

In Rust documentation there is this guideline to naming module files:

If you use both styles for the same module, you’ll get a compiler error. Using a mix of both styles for different modules in the same project is allowed, but might be confusing for people navigating your project.

The main downside to the style that uses files named mod.rs is that your project can end up with many files named mod.rs, which can get confusing when you have them open in your editor at the same time.

Maidsafe currently uses a mix of both styles. Do you mind @maidsafe if I made a PR to switch to preferred module naming?

9 Likes

Absolutely love those kind of PR’s. cc @joshuef

6 Likes

aye @loziniak that’d be grand.

I’d say we go with the modern approach? (I’m not sure what’s expected eg in the client/src/chunks we have mod but importing the other files… is that chunks.rs and chunks/error.rs ? or is that still a mod?)

4 Likes

The structure would be like that:

|
+- chunks.rs
|
+- chunks
   |
   +- pac_man.rs
   |
   +- error.rs
5 Likes

sounds good to me!

4 Likes

Here it is: move mod.rs files the modern way by loziniak Β· Pull Request #1305 Β· maidsafe/safe_network Β· GitHub

3 Likes

It makes no difference to me wrt the maidsafe crates. So this is just a general comment about rust file layouts.

I personally dislike having chunks.rs exist outside the chunks directory, effectively splitting chunks module logic into two levels. While having duplicate mod.rs open in my editor is annoying, I still prefer it to breaking up the logic for the chunks module into two separate directories.

I wish that they had done instead:

root
| - chunks
     | - chunks.rs
     | - pac_man.rs
     | - error.rs

For fun, let’s compare which looks cleaner.

new-style:

root
β”œβ”€β”€ a
β”‚   └── logic.rs
β”œβ”€β”€ a.rs
β”œβ”€β”€ b
β”‚   └── logic.rs
β”œβ”€β”€ b.rs
β”œβ”€β”€ c
β”‚   └── logic.rs
β”œβ”€β”€ c.rs
└── lib.rs

imaginary danda-style:

root
β”œβ”€β”€ a
β”‚   β”œβ”€β”€ a.rs
β”‚   └── logic.rs
β”œβ”€β”€ b
β”‚   β”œβ”€β”€ b.rs
β”‚   └── logic.rs
β”œβ”€β”€ c
β”‚   β”œβ”€β”€ c.rs
β”‚   └── logic.rs
└── lib.rs

old-style:

root
β”œβ”€β”€ a
β”‚   β”œβ”€β”€ logic.rs
β”‚   └── mod.rs
β”œβ”€β”€ b
β”‚   β”œβ”€β”€ logic.rs
β”‚   └── mod.rs
β”œβ”€β”€ c
β”‚   β”œβ”€β”€ logic.rs
β”‚   └── mod.rs
└── lib.rs

seems clear to me that new-style is ugliest.

6 Likes

Oh, I didn’t even know it’s possible. Makes sense.

1 Like

oh, I’m not saying it is possible with today’s rust compiler. afaik, the compiler only accepts the two styles you originally mentioned. I am just ranting that I think the β€œnew style” was a step backwards for the compiler/lang, and could’ve been done the way I’m suggesting instead.

So now devs are forced to choose lesser of two evils, instead of a clearly non-evil option. (my opinion).

1 Like

Checked, it’s not possible. Does not compile.

1 Like

That would be nice, true. I wonder if they have any arguments against it, perhaps it was discussed.

1 Like