summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/src/utils.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:42 +0000
commit837b550238aa671a591ccf282dddeab29cadb206 (patch)
tree914b6b8862bace72bd3245ca184d374b08d8a672 /vendor/rustix/src/utils.rs
parentAdding debian version 1.70.0+dfsg2-1. (diff)
downloadrustc-837b550238aa671a591ccf282dddeab29cadb206.tar.xz
rustc-837b550238aa671a591ccf282dddeab29cadb206.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix/src/utils.rs')
-rw-r--r--vendor/rustix/src/utils.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/vendor/rustix/src/utils.rs b/vendor/rustix/src/utils.rs
index dcbadb260..d6ad43b54 100644
--- a/vendor/rustix/src/utils.rs
+++ b/vendor/rustix/src/utils.rs
@@ -12,6 +12,26 @@ pub(crate) fn as_mut_ptr<T>(t: &mut T) -> *mut T {
t
}
+/// Convert an `Option<&T>` into a possibly-null `*const T`.
+#[inline]
+#[allow(dead_code)]
+pub(crate) const fn optional_as_ptr<T>(t: Option<&T>) -> *const T {
+ match t {
+ Some(t) => t,
+ None => core::ptr::null(),
+ }
+}
+
+/// Convert an `Option<&mut T>` into a possibly-null `*mut T`.
+#[inline]
+#[allow(dead_code)]
+pub(crate) fn optional_as_mut_ptr<T>(t: Option<&mut T>) -> *mut T {
+ match t {
+ Some(t) => t,
+ None => core::ptr::null_mut(),
+ }
+}
+
/// Convert a `*mut c_void` to a `*mut T`, checking that it is not null,
/// misaligned, or pointing to a region of memory that wraps around the address
/// space.