Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Interface helper to allow calling protocol functions #159

Merged
merged 1 commit into from
Oct 15, 2020

Conversation

udoprog
Copy link
Collaborator

@udoprog udoprog commented Oct 15, 2020

This allows for rewriting functions to receive protocols as arguments, an example of this is the now rewritten Iterator::chain:

/// Chain this iterator with another.
pub fn chain(self, other: Interface) -> Result<Self, VmError> {
    let other = other.into_iter()?;

    Ok(Self {
         inner: Inner::Chain(Box::new(Chain {
             a: Some(self.inner),
             b: Some(other.inner),
        })),
    })
}

This used to receive other: Iterator, meaning the caller has to convert the argument into an iterator. This is now instead done in the caller.

This requires the addition of a thread-local and a little bit of unsafe. Without this, we would have to pass an optional environment into every vm call, which would be messy to do with external abstractions like Function. But it also means that external abstractions will error if an environment is not available.

@udoprog udoprog added the enhancement New feature or request label Oct 15, 2020
@udoprog udoprog merged commit 6ac4b20 into master Oct 15, 2020
@udoprog udoprog deleted the interface branch October 15, 2020 01:02
@udoprog udoprog added the changelog Issue has been added to the changelog label Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog Issue has been added to the changelog enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant