Open
Description
Using a move closure inside a struct::fn
which borrows a struct
field results in corrupted memory when that closure is not move
.
Example:
extern crate fringe;
use std::iter::Iterator;
use fringe::generator::Yielder;
use fringe::{OsStack, Generator};
struct Gpx {
creator: String,
}
type Generator_<T> = fringe::Generator<(), T, fringe::OsStack>;
impl Gpx {
pub fn events<'a>(&'a self) -> Generator_<&'a str> {
let stack = OsStack::new(1 << 24).unwrap();
Generator::new(stack, |ctx, ()| { // broken
// Generator::new(stack, move |ctx, ()| { // working
ctx.suspend(self.creator.as_str());
})
}
}
fn main() {
let data = Gpx{ creator: String::from("xyz") };
println!("{:?}", data.events().next());
}
Unfortunately, I don't know if it's a problem with type checking or the unsafe portion. Given some pointers, I will try to debug it myself.
Metadata
Assignees
Labels
No labels