Skip to content

Non-const null() + as_ptr() in PCSTR, PSTR, PWSTR #2807

@smichaku

Description

@smichaku

Summary

Is there a reason not to have const {PCSTR,PSTR,PWSTR}::{null,as_ptr}() as they are for PCWSTR?

diff --git a/crates/libs/core/src/strings/pcstr.rs b/crates/libs/core/src/strings/pcstr.rs
index 5535c5ae4..d4da2c331 100644
--- a/crates/libs/core/src/strings/pcstr.rs
+++ b/crates/libs/core/src/strings/pcstr.rs
@@ -12,12 +12,12 @@ impl PCSTR {
     }

     /// Construct a null `PCSTR`
-    pub fn null() -> Self {
+    pub const fn null() -> Self {
         Self(std::ptr::null())
     }

     /// Returns a raw pointer to the `PCSTR`
-    pub fn as_ptr(&self) -> *const u8 {
+    pub const fn as_ptr(&self) -> *const u8 {
         self.0
     }

diff --git a/crates/libs/core/src/strings/pstr.rs b/crates/libs/core/src/strings/pstr.rs
index 6ea9d9c70..634b7ac03 100644
--- a/crates/libs/core/src/strings/pstr.rs
+++ b/crates/libs/core/src/strings/pstr.rs
@@ -12,12 +12,12 @@ impl PSTR {
     }

     /// Construct a null `PSTR`
-    pub fn null() -> Self {
+    pub const fn null() -> Self {
         Self(std::ptr::null_mut())
     }

     /// Returns a raw pointer to the `PSTR`
-    pub fn as_ptr(&self) -> *mut u8 {
+    pub const fn as_ptr(&self) -> *mut u8 {
         self.0
     }

diff --git a/crates/libs/core/src/strings/pwstr.rs b/crates/libs/core/src/strings/pwstr.rs
index 052bfb9cf..8ed6e7b1d 100644
--- a/crates/libs/core/src/strings/pwstr.rs
+++ b/crates/libs/core/src/strings/pwstr.rs
@@ -12,12 +12,12 @@ impl PWSTR {
     }

     /// Construct a null `PWSTR`.
-    pub fn null() -> Self {
+    pub const fn null() -> Self {
         Self(std::ptr::null_mut())
     }

     /// Returns a raw pointer to the `PWSTR`.
-    pub fn as_ptr(&self) -> *mut u16 {
+    pub const fn as_ptr(&self) -> *mut u16 {
         self.0
     }

Crate manifest

No response

Crate code

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions