Skip to content

refactor(gstd): align gstd reexports & prelude items with std#3047

Merged
fluiderson merged 11 commits into
masterfrom
as-gstd-std-alignment
Aug 22, 2023
Merged

refactor(gstd): align gstd reexports & prelude items with std#3047
fluiderson merged 11 commits into
masterfrom
as-gstd-std-alignment

Conversation

@fluiderson

Copy link
Copy Markdown
Contributor

In gstd's prelude module, the following is stated:

gear/gstd/src/prelude.rs

Lines 19 to 20 in fdb21be

//! The `gstd` default prelude. Re-imports default `std` modules and traits.
//! `std` can be safely replaced to `gstd` in the Rust programs.

That's not entirely true. Several modules and types, which can be found in std's prelude module, are missing in gstd's one. So, in this PR, I refactored the prelude module to make gstd align to std as much as possible.

The only problem here is that I'd like to leave reexports in this format for easier alignment maintaining with std, but rustfmt is configured to merge use statements. For now, I removed imports_granularity = "Crate" from rustfmt.toml, but the final solution needs to be discussed.

Comment thread rustfmt.toml
Comment thread gstd/src/prelude.rs Outdated
@ark0f

ark0f commented Aug 11, 2023

Copy link
Copy Markdown
Member

For now, I removed imports_granularity = "Crate" from rustfmt.toml, but the final solution needs to be discussed.

The line should not be removed for the whole repo because we have requirement to merge imports. It was done manually via PR author or reviewer request before.

For now I can offer to apply #![rustfmt::skip] attribute or introduce module + reexport with #[rustfmt::skip] applied.

Also, as @grishasobol said, I'm not sure we actually need to follow line by line as in std::prelude and I guess it can be replaced with glob imports (core::*, alloc::*)

@fluiderson

Copy link
Copy Markdown
Contributor Author

At first, I thought it'd be more convenient to maintain it this way if new modules would be added in core/alloc, but now I think it's easier to merge reimports than to try to exclude them from the common formatting rules.

@ark0f, glob imports create ambiguity because there are a lot of modules with the same name from core and alloc. Also I recreated some modules (e.g. collections), and they conflict with glob imports too.

Comment thread examples/fungible-token/io/src/lib.rs Outdated
Comment thread examples/waiter/src/code.rs Outdated
Comment thread gstd/src/prelude.rs Outdated
@fluiderson fluiderson merged commit 7acdbc5 into master Aug 22, 2023
@fluiderson fluiderson deleted the as-gstd-std-alignment branch August 22, 2023 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants