Skip to content

Commit 85c605d

Browse files
committed
Mark all possible functions const
1 parent a74f122 commit 85c605d

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

src/base64.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl CodePoint {
203203
)
204204
}
205205

206-
fn decode_public(a: u8) -> Self {
206+
const fn decode_public(a: u8) -> Self {
207207
const TABLE: [CodePoint; 256] = [
208208
// 0x00..0x0f
209209
CodePoint::INVALID,
@@ -502,21 +502,21 @@ fn u8_less_than(a: u8, b: u8) -> u8 {
502502
}
503503

504504
/// Returns 0xff if a == b, 0 otherwise.
505-
fn u8_equals(a: u8, b: u8) -> u8 {
505+
const fn u8_equals(a: u8, b: u8) -> u8 {
506506
let diff = a ^ b;
507507
u8_nonzero(diff)
508508
}
509509

510510
/// Returns 0xff if a != 0, 0 otherwise.
511-
fn u8_nonzero(x: u8) -> u8 {
511+
const fn u8_nonzero(x: u8) -> u8 {
512512
u8_broadcast8(!x & x.wrapping_sub(1))
513513
}
514514

515515
/// Broadcasts the top bit of `x`
516516
///
517517
/// In other words, if the top bit of `x` is set,
518518
/// returns 0xff else 0x00.
519-
fn u8_broadcast8(x: u8) -> u8 {
519+
const fn u8_broadcast8(x: u8) -> u8 {
520520
let msb = x >> 7;
521521
0u8.wrapping_sub(msb)
522522
}
@@ -525,7 +525,7 @@ fn u8_broadcast8(x: u8) -> u8 {
525525
///
526526
/// In other words, if the top bit of `x` is set,
527527
/// returns 0xff else 0x00.
528-
fn u8_broadcast16(x: u16) -> u8 {
528+
const fn u8_broadcast16(x: u16) -> u8 {
529529
let msb = x >> 15;
530530
0u8.wrapping_sub(msb as u8)
531531
}

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -959,12 +959,12 @@ impl UnixTime {
959959
/// Convert a `Duration` since the start of 1970 to a `UnixTime`
960960
///
961961
/// The `duration` must be relative to the Unix epoch.
962-
pub fn since_unix_epoch(duration: Duration) -> Self {
962+
pub const fn since_unix_epoch(duration: Duration) -> Self {
963963
Self(duration.as_secs())
964964
}
965965

966966
/// Number of seconds since the Unix epoch
967-
pub fn as_secs(&self) -> u64 {
967+
pub const fn as_secs(&self) -> u64 {
968968
self.0
969969
}
970970
}

src/pem.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub struct ReadIter<R, T> {
107107
#[cfg(feature = "std")]
108108
impl<R: io::BufRead, T: PemObject> ReadIter<R, T> {
109109
/// Create a new iterator.
110-
pub fn new(rd: R) -> Self {
110+
pub const fn new(rd: R) -> Self {
111111
Self {
112112
rd,
113113
_ty: PhantomData,
@@ -141,7 +141,7 @@ pub struct SliceIter<'a, T> {
141141

142142
impl<'a, T: PemObject> SliceIter<'a, T> {
143143
/// Create a new iterator.
144-
pub fn new(current: &'a [u8]) -> Self {
144+
pub const fn new(current: &'a [u8]) -> Self {
145145
Self {
146146
current,
147147
_ty: PhantomData,
@@ -153,7 +153,7 @@ impl<'a, T: PemObject> SliceIter<'a, T> {
153153
/// This is the slice immediately following the most
154154
/// recently returned item from `next()`.
155155
#[doc(hidden)]
156-
pub fn remainder(&self) -> &'a [u8] {
156+
pub const fn remainder(&self) -> &'a [u8] {
157157
self.current
158158
}
159159
}
@@ -371,7 +371,7 @@ pub enum SectionKind {
371371
}
372372

373373
impl SectionKind {
374-
fn secret(&self) -> bool {
374+
const fn secret(&self) -> bool {
375375
match self {
376376
Self::RsaPrivateKey | Self::PrivateKey | Self::EcPrivateKey => true,
377377
Self::Certificate | Self::PublicKey | Self::Crl | Self::Csr | Self::EchConfigList => {

src/server_name.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ mod parser {
542542
}
543543

544544
impl<'a> Parser<'a> {
545-
pub(super) fn new(input: &'a [u8]) -> Self {
545+
pub(super) const fn new(input: &'a [u8]) -> Self {
546546
Parser { state: input }
547547
}
548548

0 commit comments

Comments
 (0)