implement utility methods on partial structs#206
Merged
Conversation
jedel1043
approved these changes
Feb 24, 2025
Member
jedel1043
left a comment
There was a problem hiding this comment.
I think this makes sense. Moving structs is much safer for FFI than passing references, since it's harder to preserve the mutable borrow XOR shared borrow rule.
jedel1043
requested changes
Feb 24, 2025
Comment on lines
+128
to
+165
| /// Convenience methods for building a `PartialDate` | ||
| impl PartialDate { | ||
| pub const fn with_era(mut self, era: Option<TinyAsciiStr<19>>) -> Self { | ||
| self.era = era; | ||
| self | ||
| } | ||
|
|
||
| pub const fn with_era_year(mut self, era_year: Option<i32>) -> Self { | ||
| self.era_year = era_year; | ||
| self | ||
| } | ||
|
|
||
| pub const fn with_year(mut self, year: Option<i32>) -> Self { | ||
| self.year = year; | ||
| self | ||
| } | ||
|
|
||
| pub const fn with_month(mut self, month: Option<u8>) -> Self { | ||
| self.month = month; | ||
| self | ||
| } | ||
|
|
||
| pub const fn with_month_code(mut self, month_code: Option<TinyAsciiStr<4>>) -> Self { | ||
| self.month_code = month_code; | ||
| self | ||
| } | ||
|
|
||
| pub const fn with_day(mut self, day: Option<u8>) -> Self { | ||
| self.day = day; | ||
| self | ||
| } | ||
|
|
||
| pub const fn with_calendar(mut self, calendar: Calendar) -> Self { | ||
| self.calendar = calendar; | ||
| self | ||
| } | ||
| } | ||
|
|
Member
There was a problem hiding this comment.
Now that I think about this, can you add a const new constructor? Having all of these be const is useful, but they're less useful because we don't have a way to ergonomically create a const PartialDate without having to manually set all fields to None...
Member
Author
There was a problem hiding this comment.
I tried to add a const new as well. But it requires a const calendar constructor, which was ultimately the blocker. I'll play around with it a bit more.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds methods with the goal of making Partials structs a bit more ergonomic to work with rather than using only struct expressions.
Before:
After:
If this doesn't make much sense and it's preferred to keep the current method of
StructExpressions