Ensure that the Input/Output types outlive the generator [breaking-change]
Previously, it was possible to cause unsafety by sending a short-lived value into or out of the generator.
This commit is contained in:
parent
59f28e92cb
commit
045ad33785
|
@ -80,7 +80,7 @@ pub enum State {
|
||||||
/// println!("{:?}", nat.next()); // prints Some(2)
|
/// println!("{:?}", nat.next()); // prints Some(2)
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Generator<'a, Input: Send, Output: Send, Stack: stack::Stack> {
|
pub struct Generator<'a, Input: Send + 'a, Output: Send + 'a, Stack: stack::Stack> {
|
||||||
state: State,
|
state: State,
|
||||||
stack: Stack,
|
stack: Stack,
|
||||||
stack_id: debug::StackId,
|
stack_id: debug::StackId,
|
||||||
|
@ -89,7 +89,7 @@ pub struct Generator<'a, Input: Send, Output: Send, Stack: stack::Stack> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Input, Output, Stack> Generator<'a, Input, Output, Stack>
|
impl<'a, Input, Output, Stack> Generator<'a, Input, Output, Stack>
|
||||||
where Input: Send, Output: Send, Stack: stack::Stack {
|
where Input: Send + 'a, Output: Send + 'a, Stack: stack::Stack {
|
||||||
/// Creates a new generator.
|
/// Creates a new generator.
|
||||||
///
|
///
|
||||||
/// See also the [contract](../trait.GuardedStack.html) that needs to be fulfilled by `stack`.
|
/// See also the [contract](../trait.GuardedStack.html) that needs to be fulfilled by `stack`.
|
||||||
|
@ -219,7 +219,7 @@ impl<Input, Output> Yielder<Input, Output>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Output, Stack> Iterator for Generator<'a, (), Output, Stack>
|
impl<'a, Output, Stack> Iterator for Generator<'a, (), Output, Stack>
|
||||||
where Output: Send, Stack: stack::Stack {
|
where Output: Send + 'a, Stack: stack::Stack {
|
||||||
type Item = Output;
|
type Item = Output;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> { self.resume(()) }
|
fn next(&mut self) -> Option<Self::Item> { self.resume(()) }
|
||||||
|
|
Loading…
Reference in New Issue