diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:42 +0000 |
commit | 837b550238aa671a591ccf282dddeab29cadb206 (patch) | |
tree | 914b6b8862bace72bd3245ca184d374b08d8a672 /vendor/rustix/src/utils.rs | |
parent | Adding debian version 1.70.0+dfsg2-1. (diff) | |
download | rustc-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.rs | 20 |
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. |