Skip to content

Commit 0ad4303

Browse files
tormolThomas Bahn
authored andcommitted
Constify a tiny few AsciiStr methods
* as_slice() * as_ptr() * AsAsciiStrError::valid_up_to() * #![no_std] AsAsciiStrError::description() All other methods either require pointer "dereferencing", branching, calling not yet const fn std methods or return impl Trait.
1 parent 0323050 commit 0ad4303

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/ascii_str.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl AsciiStr {
3939

4040
/// Returns the entire string as slice of `AsciiChar`s.
4141
#[inline]
42-
pub fn as_slice(&self) -> &[AsciiChar] {
42+
pub const fn as_slice(&self) -> &[AsciiChar] {
4343
&self.slice
4444
}
4545

@@ -55,7 +55,7 @@ impl AsciiStr {
5555
/// will end up pointing to garbage. Modifying the `AsciiStr` may cause it's buffer to be
5656
/// reallocated, which would also make any pointers to it invalid.
5757
#[inline]
58-
pub fn as_ptr(&self) -> *const AsciiChar {
58+
pub const fn as_ptr(&self) -> *const AsciiChar {
5959
self.as_slice().as_ptr()
6060
}
6161

@@ -683,13 +683,13 @@ impl AsAsciiStrError {
683683
///
684684
/// It is the maximum index such that `from_ascii(input[..index])` would return `Ok(_)`.
685685
#[inline]
686-
pub fn valid_up_to(self) -> usize {
686+
pub const fn valid_up_to(self) -> usize {
687687
self.0
688688
}
689689
#[cfg(not(feature = "std"))]
690690
/// Returns a description for this error, like `std::error::Error::description`.
691691
#[inline]
692-
pub fn description(&self) -> &'static str {
692+
pub const fn description(&self) -> &'static str {
693693
ERRORMSG_STR
694694
}
695695
}

0 commit comments

Comments
 (0)