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

#[carol] should generate a remote calling interface #4

Open
LLFourn opened this issue Apr 14, 2023 · 0 comments
Open

#[carol] should generate a remote calling interface #4

LLFourn opened this issue Apr 14, 2023 · 0 comments
Labels

Comments

@LLFourn
Copy link
Collaborator

LLFourn commented Apr 14, 2023

Take this test for example:

#[carol]
impl Foo {
    #[activate]
    pub fn add(&self, lhs: u32, rhs: u32) -> u32 {
        lhs + rhs
    }

    #[activate]
    pub fn checked_sub(&self, lhs: u32, rhs: u32) -> Option<u32> {
        lhs.checked_sub(rhs)
    }

    pub fn non_activate(&self) {
        unreachable!()
    }

}

use carol_activate::{Activate, Add, CheckedSub};


#[test]
fn call_add() {
    let method = Activate::Add(Add { lhs: 7, rhs: 3 });
    let call = bincode::encode_to_vec(method, bincode::config::standard()).unwrap();
    let foo = Foo;
    let output = Foo::activate(
        bincode::encode_to_vec(foo, bincode::config::standard()).unwrap(),
        call,
    );
    let (result, _): (u32, _) =
        bincode::decode_from_slice(&output, bincode::config::standard()).unwrap();
    assert_eq!(result, 10);
}

In that test I think I should be able to just do:

    let foo = Foo;
    let (input, decoder) = input_gen::add(7, 3);
    let output = Foo::activate(
        bincode::encode_to_vec(foo, bincode::config::standard()).unwrap(),
        call,
    );
    let output = decoder.decode(output)?;
    assert_eq!(output, 10);

where input_gen is codegen'd by the macro.

This is useful so you can easily activate from client code without having to construct enum variants manually.

@LLFourn LLFourn added the v0 label May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant