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

Minor refactor and cleanup #716

Merged
merged 3 commits into from
Jun 15, 2023
Merged

Minor refactor and cleanup #716

merged 3 commits into from
Jun 15, 2023

Conversation

nyurik
Copy link
Member

@nyurik nyurik commented Jun 15, 2023

  • moved IdResolver to a separate file
  • added just fmt2 build target to format code using nightly mode
  • moved all Actix Data<AppState> into individual state objects, e.g. Data<Sources> (allows other source types, separate from Sources type)
  • move all Source-related code to a new Sources struct (a simple wrapper over a HashMap)

use sqlx::{query, SqliteExecutor};

use crate::errors::MbtResult;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this because the imports of things that are in the crate should be kept separate? It looks like if we use rustfmt-nightly we can configure this by default by specifying

reorder_imports_in_group = true

in the rustfmt.toml file (link1, link2).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@upsicleclown do you mean why it has been moved to a separate line separated by a blank line? We have a few config options already set - https://github.com/maplibre/martin/blob/main/rustfmt.toml - but I don't want to enable it "by default" because the stable rustfmt throws an error if rustfmt has some settings it does not support. So keeping it commented out.

Note that reorder_imports_in_group seem to have been removed - try adding it to rustfmt and running cargo +nightly fmt - and it will complain.

I added a fmt2 just target to do it from CLI

This will simplify some planned work
@nyurik nyurik enabled auto-merge (squash) June 15, 2023 20:59
pub fn extract_file_config(&mut self) -> FileConfig {
match self {
FileConfigEnum::Path(path) => FileConfig {
paths: Some(OneOrMany::One(mem::take(path))),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This looked cleaner when One and Many were imported directly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed. This one is kinda tricky because often when you see One, it might not give enough context - so i have seen a lot of things like io::Result when things are not extra clear.


impl Sources {
pub fn insert(&mut self, id: String, source: Box<dyn Source>) {
self.0.insert(id, source);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: It might be worth giving the HashMap in Sources a name, so that the accesses are clearer

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a fairly common pattern - esp when there is only one value wrapped. I would rather not change it to a named struct

@nyurik nyurik disabled auto-merge June 15, 2023 22:29
@nyurik nyurik merged commit 7e20602 into maplibre:main Jun 15, 2023
16 checks passed
@nyurik nyurik deleted the refactr branch June 15, 2023 22:36
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.

2 participants