mirror of
https://github.com/Noratrieb/stuff.git
synced 2026-01-16 01:15:07 +01:00
get drop working
This commit is contained in:
parent
74bd6e064f
commit
a453f210b3
2 changed files with 38 additions and 12 deletions
|
|
@ -21,6 +21,27 @@ pub mod test_strategies {
|
|||
use crate::StuffingStrategy;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
|
||||
macro_rules! impl_usize_max_zst {
|
||||
($ty:ident) => {
|
||||
// this one lives in usize::MAX
|
||||
unsafe impl StuffingStrategy for $ty {
|
||||
type Extra = Self;
|
||||
|
||||
fn is_extra(data: usize) -> bool {
|
||||
data == usize::MAX
|
||||
}
|
||||
|
||||
fn stuff_extra(_inner: Self::Extra) -> usize {
|
||||
usize::MAX
|
||||
}
|
||||
|
||||
fn extract_extra(_data: usize) -> Self::Extra {
|
||||
$ty
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub struct HasDebug;
|
||||
|
||||
impl Debug for HasDebug {
|
||||
|
|
@ -29,19 +50,15 @@ pub mod test_strategies {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl StuffingStrategy for HasDebug {
|
||||
type Extra = Self;
|
||||
impl_usize_max_zst!(HasDebug);
|
||||
|
||||
fn is_extra(data: usize) -> bool {
|
||||
data == usize::MAX
|
||||
}
|
||||
pub struct PanicsInDrop;
|
||||
|
||||
fn stuff_extra(_inner: Self::Extra) -> usize {
|
||||
usize::MAX
|
||||
}
|
||||
|
||||
fn extract_extra(_data: usize) -> Self::Extra {
|
||||
Self
|
||||
impl Drop for PanicsInDrop {
|
||||
fn drop(&mut self) {
|
||||
panic!("oh no!!!");
|
||||
}
|
||||
}
|
||||
|
||||
impl_usize_max_zst!(PanicsInDrop);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue