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:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/rustix/src/utils.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.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.