Skip to content

Commit eed33a9

Browse files
bors[bot]CAD97
andauthored
Merge #60
60: Add PtrUnion::as_untagged_ptr r=CAD97 a=CAD97 Co-authored-by: CAD97 <[email protected]>
2 parents 4d54f90 + 501e4c4 commit eed33a9

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

crates/ptr-union/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ by storing the tag in the alignment bits.
33

44
## Changelist
55

6+
### 2.1.0
7+
#### Added
8+
9+
- `fn Union*::as_untagged_ptr(&self) -> ErasedPtr`
10+
611
### 2.0.0
712
#### Fixes
813

crates/ptr-union/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ fn unset_tag(ptr: ErasedPtr, mask: usize, tag: usize) -> ErasedPtr {
4444
unsafe { ErasedPtr::new_unchecked((ptr.as_ptr() as usize & !mask) as *mut _) }
4545
}
4646

47+
#[inline(always)]
48+
fn unset_any_tag(ptr: ErasedPtr, mask: usize) -> ErasedPtr {
49+
unsafe { ErasedPtr::new_unchecked((ptr.as_ptr() as usize & !mask) as *mut _) }
50+
}
51+
4752
#[cfg(has_never)]
4853
pub type NeverPtr = !;
4954
#[cfg(not(has_never))]
@@ -248,6 +253,11 @@ macro_rules! impl_union {
248253
.unwrap_or_else(|_| unsafe { unreachable_unchecked() })
249254
}
250255
}
256+
257+
/// Get the raw type-erased untagged pointer to the payload.
258+
pub fn as_untagged_ptr(&self) -> ErasedPtr {
259+
unset_any_tag(self.raw, $mask)
260+
}
251261
}
252262

253263
impl<$($A: ErasablePtr),*> $Enum<$($A),*> {

0 commit comments

Comments
 (0)