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

[valor-plugin] Add support for structs #9

Merged
merged 1 commit into from
Nov 26, 2020

Conversation

c410-f3r
Copy link
Contributor

@c410-f3r c410-f3r commented Nov 26, 2020

Fixes #3

Also adds basic documentation and Debug implementations

use valor::*;

#[vlugin]
#[derive(Default)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary because RequestHandler::handle_request expects an instance

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I think it can be polished in #8 luckily it's not needed later to have a that magical feeling of "Add macro and just works"

Copy link
Member

@olanod olanod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First code contribution! yay! 🎆 Looks good, just some comments


Error::new(
proc_macro2::Span::mixed_site(),
"Only functions and structures that implement `RequestHandler` are currently supported",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄 👍🏽

src/registry.rs Outdated
@@ -56,7 +57,7 @@ impl PluginRegistry {
Box::new(move |mut req: Request| {
let registry = self.clone();
let loader = loader.clone();
Box::pin(async move {
let rslt: HandlerResponse = Box::pin(async move {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you say using as ... is an anti-pattern? matter of preference? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes as is dangerous, for example, 1000u128 as u8.

All as where removed because trivial_casts was on and I am going to revert these specific changes to remove noise

use valor::*;

#[vlugin]
fn hello_plugin(_req: Request) -> Response {
"Hello Plugin!".into()
}

fn main() {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the intended use is as dynlib, making the examples executable might be confusing. It would be cool if after building the examples and running valor-native the user can register them(currently only with the _plugins endpoint) and see how they respond. Perhaps a script can take care of the building, running the api and register them? E.g. in https://github.com/valibre-org/vln-api I created a Makefile to compile the plugins and put them in a directory that is more accessible(that can later be published). Maybe when implementing #6 can get nicer if the plugins are auto-loaded from a directory or passing a file that can be easily deserialized to a collection of Plugins.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the lack of attention. I will revert it back to a library

use valor::*;

#[vlugin]
#[derive(Default)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I think it can be polished in #8 luckily it's not needed later to have a that magical feeling of "Add macro and just works"

#[no_mangle]
pub extern "Rust" fn get_request_handler() -> Box<dyn valor::RequestHandler> {
Box::new({
let fun = |req| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need the wrapping function if instance is already a RequestHandler?

@olanod
Copy link
Member

olanod commented Nov 26, 2020

Looks good! :)

@olanod olanod merged commit 524d8b5 into virto-network:main Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[vlugin] Support structs
2 participants