Expose unsafe_unwrap
This at least ensures we don't have to needlessly leak generators in the tests, and covers similar use cases for consumers of libfringe.
This commit is contained in:
parent
d49557a55a
commit
df7f261ca6
@ -8,7 +8,6 @@
|
||||
extern crate test;
|
||||
extern crate fringe;
|
||||
|
||||
use std::mem;
|
||||
use fringe::{OsStack, Generator};
|
||||
|
||||
#[bench]
|
||||
@ -19,5 +18,5 @@ fn generate(b: &mut test::Bencher) {
|
||||
});
|
||||
|
||||
b.iter(|| for _ in 0..10 { test::black_box(identity.resume(test::black_box(0))); });
|
||||
mem::forget(identity);
|
||||
unsafe { identity.unsafe_unwrap(); }
|
||||
}
|
||||
|
@ -201,7 +201,9 @@ impl<'a, Input, Output, Stack> Generator<'a, Input, Output, Stack>
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn unsafe_unwrap(mut self) -> Stack {
|
||||
/// Extracts the stack from a generator without checking if the generator function has returned.
|
||||
/// This will leave any pointers into the generator stack dangling, and won't run destructors.
|
||||
pub unsafe fn unsafe_unwrap(mut self) -> Stack {
|
||||
ptr::drop_in_place(&mut self.stack_id.value);
|
||||
let stack = ptr::read(&mut self.stack.value);
|
||||
mem::forget(self);
|
||||
|
@ -8,7 +8,6 @@ extern crate fringe;
|
||||
|
||||
use fringe::OsStack;
|
||||
use fringe::generator::Generator;
|
||||
use std::mem;
|
||||
|
||||
#[test]
|
||||
fn producer() {
|
||||
@ -19,5 +18,5 @@ fn producer() {
|
||||
assert_eq!(gen.next(), Some(0));
|
||||
assert_eq!(gen.next(), Some(1));
|
||||
assert_eq!(gen.next(), Some(2));
|
||||
mem::forget(gen);
|
||||
unsafe { gen.unsafe_unwrap(); }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user