Skip to content
Discussion options

You must be logged in to vote

The reason this doesn't work is that it's not sound. You can't keep a Term<'a> outside of the lifetime of the respective Env<'a> (which corresponds to a NifEnv*). What you can do instead is creating an OwnedEnv to keep a SavedTerm around that you can later use in a run or send call.

pub struct LocalMessage {
    pid: LocalPid,
    env: OwnedEnv,
    term: SavedTerm,
}

impl LocalMessage {
    pub new<'a>(pid: LocalPid, term: Term<'a>) -> Self {
        let env = OwnedEnv::new();
        let term = env.save(term);
        Self { env, pid, term }
    }

    // Consumes self
    pub fn send(self) -> Result<(), SendError> {
        self.env.send_and_clear(|env| env.load(self.term));
    }
}

I…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by filmor
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants