refactor(DisplaySettings): use Options for default fields #161

Merged
ada4a merged 3 commits from ada4a/mergiraf:display_settings_default_fields into main 2025-01-22 11:56:56 +01:00
Owner

Previously, we needed to specify the default values in multiple places:

  • the two default{,_compact} constructors
  • in the binary, as default_*_name
  • also in the binary, as the default values for flags

This commit removes all those and uses Nones in there, instead adding methods called DisplaySettings::<field_name>_or_default that return Some values if they exist, or the actual defaults in case of None.

There was another approach that came to mind, but was seen as too cumbersome: make a newtype for each such field, and implement Default for them -- this'd requier too much boilerplate and could require exposing the newtypes in a lot of places (most importantly, in the binary).

Ideally, of course, we'd use default field values, but those aren't stabilzed yet.1

This also gets rid of the TODO in mergiraf solve, which was addressed back in #74

Previously, we needed to specify the default values in multiple places: - the two `default{,_compact}` constructors - in the binary, as `default_*_name` - also in the binary, as the default values for flags This commit removes all those and uses `None`s in there, instead adding methods called `DisplaySettings::<field_name>_or_default` that return `Some` values if they exist, or the _actual_ defaults in case of `None`. There was another approach that came to mind, but was seen as too cumbersome: make a newtype for each such field, and implement `Default` for them -- this'd requier too much boilerplate and could require exposing the newtypes in a lot of places (most importantly, in the binary). Ideally, of course, we'd use default field values, but those aren't stabilzed yet.[^1] This also gets rid of the TODO in `mergiraf solve`, which was addressed back in #74 [^1]: https://github.com/rust-lang/rust/issues/132162
refactor(DisplaySettings): use Options for default fields
All checks were successful
/ test (pull_request) Successful in 1m24s
4815b1aeea
Previously, we needed to specify the default values in multiple places:
- the two `default{,_compact}` constructors
- in the binary, as `default_*_name`
- also in the binary, as the default values for flags

This commit removes all those and uses `None`s in there, instead adding
methods called `DisplaySettings::<field_name>_or_default` that return
`Some` values if they exist, or the _actual_ defaults in case of `None`.

There was another approach that came to mind, but was seen as too
cumbersome: make a newtype for each such field, and implement `Default`
for them -- this'd requier too much boilerplate and could require
exposing the newtypes in a lot of places (most importantly, in the
binary).

Ideally, of course, we'd use default field values, but those aren't
stabilzed yet.[^1]

This also gets rid of the TODO in `mergiraf solve`, which was addressed
back in #74

[^1]: https://github.com/rust-lang/rust/issues/132162
src/settings.rs Outdated
@ -23,1 +48,3 @@
pub fn left_marker(&self) -> String {
/// Uses the default values of `conflict_marker_size` and `left_revision_name` if not set
pub fn left_marker_or_default(&self) -> String {
println!("called left_marker_or_default");
Owner

We could remove this println :)

We could remove this `println` :)
Author
Owner

when you think you've checked everything a hundred times... thanks, fixed!

when you think you've checked everything a hundred times... thanks, fixed!
wetneb marked this conversation as resolved
rm dbgprint
All checks were successful
/ test (pull_request) Successful in 1m17s
0137a190c6
misc: use default struct initialization
All checks were successful
/ test (pull_request) Successful in 1m19s
053f0bf11f
wetneb approved these changes 2025-01-22 11:55:47 +01:00
ada4a merged commit 2581362617 into main 2025-01-22 11:56:56 +01:00
ada4a deleted branch display_settings_default_fields 2025-01-22 11:57:00 +01:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: mergiraf/mergiraf#161
No description provided.