Skip to content

Commit b3ad057

Browse files
committed
const fn wherever possible
1 parent 21c40d6 commit b3ad057

File tree

12 files changed

+23
-22
lines changed

12 files changed

+23
-22
lines changed

src/data_types/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl Event {
5151
/// to it are invalidated and the underlying memory is freed by firmware. The caller must ensure
5252
/// that any clones of a closed `Event` are never used again.
5353
#[must_use]
54-
pub unsafe fn unsafe_clone(&self) -> Self {
54+
pub const unsafe fn unsafe_clone(&self) -> Self {
5555
Self(self.0)
5656
}
5757
}

src/data_types/strs.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ impl CStr8 {
100100
///
101101
/// It's the callers responsibility to ensure chars is a valid Latin-1
102102
/// null-terminated string, with no interior null bytes.
103-
pub unsafe fn from_bytes_with_nul_unchecked(chars: &[u8]) -> &Self {
103+
pub const unsafe fn from_bytes_with_nul_unchecked(chars: &[u8]) -> &Self {
104104
&*(chars as *const [u8] as *const Self)
105105
}
106106

107107
/// Returns the inner pointer to this CStr8.
108-
pub fn as_ptr(&self) -> *const Char8 {
108+
pub const fn as_ptr(&self) -> *const Char8 {
109109
self.0.as_ptr()
110110
}
111111

@@ -116,7 +116,7 @@ impl CStr8 {
116116
}
117117

118118
/// Converts this CStr8 to a slice of bytes containing the trailing null byte.
119-
pub fn to_bytes_with_nul(&self) -> &[u8] {
119+
pub const fn to_bytes_with_nul(&self) -> &[u8] {
120120
unsafe { &*(&self.0 as *const [Char8] as *const [u8]) }
121121
}
122122
}
@@ -304,12 +304,12 @@ impl CStr16 {
304304
}
305305

306306
/// Converts this C string to a u16 slice containing the trailing 0 char
307-
pub fn to_u16_slice_with_nul(&self) -> &[u16] {
307+
pub const fn to_u16_slice_with_nul(&self) -> &[u16] {
308308
unsafe { &*(&self.0 as *const [Char16] as *const [u16]) }
309309
}
310310

311311
/// Returns an iterator over this C string
312-
pub fn iter(&self) -> CStr16Iter {
312+
pub const fn iter(&self) -> CStr16Iter {
313313
CStr16Iter {
314314
inner: self,
315315
pos: 0,

src/data_types/unaligned_slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<'a, T: Copy> UnalignedSlice<'a, T> {
5858
/// Returns an iterator over the slice.
5959
///
6060
/// The iterator yields all items from start to end.
61-
pub fn iter(&'a self) -> UnalignedSliceIter<'a, T> {
61+
pub const fn iter(&'a self) -> UnalignedSliceIter<'a, T> {
6262
UnalignedSliceIter {
6363
slice: self,
6464
index: 0,

src/proto/console/gop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ pub struct BltPixel {
475475

476476
impl BltPixel {
477477
/// Create a new pixel from RGB values.
478-
pub fn new(red: u8, green: u8, blue: u8) -> Self {
478+
pub const fn new(red: u8, green: u8, blue: u8) -> Self {
479479
Self {
480480
red,
481481
green,

src/proto/device_path/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl DevicePathNode {
130130
}
131131

132132
/// Cast to a [`FfiDevicePath`] pointer.
133-
pub fn as_ffi_ptr(&self) -> *const FfiDevicePath {
133+
pub const fn as_ffi_ptr(&self) -> *const FfiDevicePath {
134134
let ptr: *const Self = self;
135135
ptr.cast::<FfiDevicePath>()
136136
}
@@ -215,7 +215,7 @@ impl DevicePathInstance {
215215
/// reached.
216216
///
217217
/// [`DevicePathNodes`]: DevicePathNode
218-
pub fn node_iter(&self) -> DevicePathNodeIterator {
218+
pub const fn node_iter(&self) -> DevicePathNodeIterator {
219219
DevicePathNodeIterator {
220220
nodes: &self.data,
221221
stop_condition: StopCondition::AnyEndNode,
@@ -287,7 +287,7 @@ impl DevicePath {
287287
}
288288

289289
/// Get an iterator over the [`DevicePathInstance`]s in this path.
290-
pub fn instance_iter(&self) -> DevicePathInstanceIterator {
290+
pub const fn instance_iter(&self) -> DevicePathInstanceIterator {
291291
DevicePathInstanceIterator {
292292
remaining_path: Some(self),
293293
}
@@ -297,7 +297,7 @@ impl DevicePath {
297297
/// `self`. Iteration ends when a path is reached where
298298
/// [`is_end_entire`][DevicePathNode::is_end_entire] is true. That ending
299299
/// path is not returned by the iterator.
300-
pub fn node_iter(&self) -> DevicePathNodeIterator {
300+
pub const fn node_iter(&self) -> DevicePathNodeIterator {
301301
DevicePathNodeIterator {
302302
nodes: &self.data,
303303
stop_condition: StopCondition::EndEntireNode,

src/proto/media/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct BlockIO {
3131

3232
impl BlockIO {
3333
/// Pointer for block IO media.
34-
pub fn media(&self) -> &BlockIOMedia {
34+
pub const fn media(&self) -> &BlockIOMedia {
3535
unsafe { &*self.media }
3636
}
3737

src/proto/media/file/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl<T: File> FileInternal for T {}
248248
pub struct FileHandle(*mut FileImpl);
249249

250250
impl FileHandle {
251-
pub(super) unsafe fn new(ptr: *mut FileImpl) -> Self {
251+
pub(super) const unsafe fn new(ptr: *mut FileImpl) -> Self {
252252
Self(ptr)
253253
}
254254

src/proto/network/pxe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ impl BaseCode {
611611
}
612612

613613
/// Returns a reference to the `Mode` struct.
614-
pub fn mode(&self) -> &Mode {
614+
pub const fn mode(&self) -> &Mode {
615615
unsafe { &*self.mode }
616616
}
617617
}

src/result/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ impl<Data: Debug> Error<Data> {
2626
}
2727

2828
/// Split this error into its inner status and error data
29+
#[allow(clippy::missing_const_for_fn)]
2930
pub fn split(self) -> (Status, Data) {
3031
(self.status, self.data)
3132
}

src/table/boot.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,7 @@ pub enum SearchType<'guid> {
17181718

17191719
impl<'guid> SearchType<'guid> {
17201720
/// Constructs a new search type for a specified protocol.
1721-
pub fn from_proto<P: Protocol>() -> Self {
1721+
pub const fn from_proto<P: Protocol>() -> Self {
17221722
SearchType::ByProtocol(&P::GUID)
17231723
}
17241724
}
@@ -1794,7 +1794,7 @@ impl<'a> Drop for ProtocolsPerHandle<'a> {
17941794
impl<'a> ProtocolsPerHandle<'a> {
17951795
/// Get the protocol interface [`Guids`][Guid] that are installed on the
17961796
/// [`Handle`].
1797-
pub fn protocols<'b>(&'b self) -> &'b [&'a Guid] {
1797+
pub const fn protocols<'b>(&'b self) -> &'b [&'a Guid] {
17981798
// convert raw pointer to slice here so that we can get
17991799
// appropriate lifetime of the slice.
18001800
unsafe { slice::from_raw_parts(self.protocols, self.count) }
@@ -1820,7 +1820,7 @@ impl<'a> Drop for HandleBuffer<'a> {
18201820

18211821
impl<'a> HandleBuffer<'a> {
18221822
/// Get an array of [`Handles`][Handle] that support the requested protocol.
1823-
pub fn handles(&self) -> &[Handle] {
1823+
pub const fn handles(&self) -> &[Handle] {
18241824
// convert raw pointer to slice here so that we can get
18251825
// appropriate lifetime of the slice.
18261826
unsafe { slice::from_raw_parts(self.buffer, self.count) }

src/table/runtime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ impl Time {
405405
///
406406
/// [`FileInfo`]: uefi::proto::media::file::FileInfo
407407
/// [`File::set_info`]: uefi::proto::media::file::File::set_info
408-
pub fn invalid() -> Self {
408+
pub const fn invalid() -> Self {
409409
Self {
410410
year: 0,
411411
month: 0,

src/table/system.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<View: SystemTableView> SystemTable<View> {
7070

7171
/// Returns the config table entries, a linear array of structures
7272
/// pointing to other system-specific tables.
73-
pub fn config_table(&self) -> &[cfg::ConfigTableEntry] {
73+
pub const fn config_table(&self) -> &[cfg::ConfigTableEntry] {
7474
unsafe { slice::from_raw_parts(self.table.cfg_table, self.table.nr_cfg) }
7575
}
7676

@@ -125,7 +125,7 @@ impl SystemTable<Boot> {
125125
}
126126

127127
/// Access boot services
128-
pub fn boot_services(&self) -> &BootServices {
128+
pub const fn boot_services(&self) -> &BootServices {
129129
unsafe { &*self.table.boot }
130130
}
131131

@@ -220,7 +220,7 @@ impl SystemTable<Boot> {
220220
/// designs that Rust uses for memory allocation, logging, and panic
221221
/// handling require taking this risk.
222222
#[must_use]
223-
pub unsafe fn unsafe_clone(&self) -> Self {
223+
pub const unsafe fn unsafe_clone(&self) -> Self {
224224
SystemTable {
225225
table: self.table,
226226
_marker: PhantomData,

0 commit comments

Comments
 (0)