Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Make new unchecked unsafe #72

Open
@Toorero

Description

I was just reading your code and was wondering what's up with the Day::__new_unchecked function.

Wouldn't it make more sense to "really" expose it publicly and make it unsafe, so that the caller has to take care to uphold safety?

diff --git a/src/template/day.rs b/src/template/day.rs
--- a/src/template/day.rs
+++ b/src/template/day.rs
@@ -31,9 +31,12 @@ impl Day {
 Some(Self(day))
 }
 
- // Not part of the public API
- #[doc(hidden)]
- pub const fn __new_unchecked(day: u8) -> Self {
+ /// Creates a new day without checking if it's in the valid range.
+ ///
+ /// # Safety
+ ///
+ /// Ensure that day is in range `1..=24`.
+ pub const unsafe fn new_unchecked(day: u8) -> Self {
 Self(day)
 }
 
@@ -146,7 +149,7 @@ macro_rules! day {
 "`, expecting a value between 1 and 25"
 ),
 );
- $crate::template::Day::__new_unchecked($day)
+ unsafe { $crate::template::Day::new_unchecked($day) }
 }};
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /