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

chore(path): make path reading api more rusty #9103

Merged
merged 1 commit into from
Sep 3, 2024

Conversation

chris-olszewski
Copy link
Member

Description

Remove read_existing_to_string_or in favor of read_existing_to_string to consolidate on the more Rust-y API for reading a path to a file.

read_existing_to_string_or is an awkward API due:

  • It conflates two outcomes: The file not existing and the file existing with the contents of the default
  • The default is provided as Result<impl Into<String>, io::Error>. impl Into<String> was chosen so unnecessary work could be avoided. This is limiting compared to FnOnce() -> String.
  • It prevents us from using the battle tested Option API

The benefits of not conflating the two outcomes is best displayed when trying to read a config file. Instead of defaulting having a default of {} and then parsing it as JSON we can skip the parse and just use ConfigurationOptions::default()

Testing Instructions

Existing unit tests + 👀

Copy link

vercel bot commented Sep 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
examples-nonmonorepo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 3, 2024 7:18pm
8 Skipped Deployments
Name Status Preview Comments Updated (UTC)
examples-basic-web ⬜️ Ignored (Inspect) Sep 3, 2024 7:18pm
examples-designsystem-docs ⬜️ Ignored (Inspect) Sep 3, 2024 7:18pm
examples-gatsby-web ⬜️ Ignored (Inspect) Sep 3, 2024 7:18pm
examples-kitchensink-blog ⬜️ Ignored (Inspect) Sep 3, 2024 7:18pm
examples-native-web ⬜️ Ignored (Inspect) Sep 3, 2024 7:18pm
examples-svelte-web ⬜️ Ignored (Inspect) Sep 3, 2024 7:18pm
examples-tailwind-web ⬜️ Ignored (Inspect) Sep 3, 2024 7:18pm
examples-vite-web ⬜️ Ignored (Inspect) Sep 3, 2024 7:18pm

Copy link
Contributor

@NicholasLYang NicholasLYang left a comment

Choose a reason for hiding this comment

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

Didn't even realize we had this API

@chris-olszewski chris-olszewski enabled auto-merge (squash) September 3, 2024 19:30
@chris-olszewski chris-olszewski merged commit 0f7ef21 into main Sep 3, 2024
39 checks passed
@chris-olszewski chris-olszewski deleted the olszewski/chore_rusty_read_api branch September 3, 2024 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants