-
Notifications
You must be signed in to change notification settings - Fork 1
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
Use derive to automatically opt in operations #47
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Teo Koon Peng <[email protected]>
Signed-off-by: Teo Koon Peng <[email protected]>
Signed-off-by: Teo Koon Peng <[email protected]>
Signed-off-by: Teo Koon Peng <[email protected]>
Signed-off-by: Teo Koon Peng <[email protected]>
I'm guessing the introducing of tbh, the current node based serialization is causing extra complexities, it is possible for 2 nodes with the same req/resp to register with different options (e.g. one can serialize, another cannot), so there are situations where we need to disallow serialization even if we can technically do it. A message based registry would also help in #44. |
Yep this is the intention, but that would've been a bigger refactor than what I was prepared to do for #27 . I'm fully supportive of moving in that direction, but we'll probably need to rethink the node metadata as well. Maybe the node metadata should contain the typename of the message types (I think |
My concern with the derive approach remains the fact that we can't use it for types like I worry that introducing derive for this will be confusing because it creates two different situational ways to do the same thing. It would probably be easier to provide users with direct and consistent instructions on how to get all their operations registered that work for all scenarios. The only truly nice solution to the problem will be to use |
I have considered using some string based typename before, but the mean issue is that
I wouldn't say it is a blocker as serde (and pretty much every derive) has the same problem.
#[derive(DiagramMessage)]
struct WrappedMessage(Base);
Yeah I agree multiple ways to do things is not good. But we can put this behind a feature flag, and document only the preferred way. clap has the same issue as well, it supports both the derive API and the builder API, it mostly advertise the derive API but the builder API is still there (you could even say the builder API is the "default" as the derive API is behind a feature flag). I don't think we can use |
New feature implementation
Implemented feature
Allows certain ops like
unzip
to be automatically opt in if it is eligible.Implementation description
This is still very experimental, mostly a POC at this point. This PR uses derive to automatically impl a new
DiagramMessage
trait for structs that are used as request/response in nodes. There is a newregister_with_diagram_message
(temp name) function that acts likeregister_node_builder
, except it requires the nodes to have req/resp that implsDiagramMessage
. In this POC, only unzip is implemented, but in theory we should be able to do it for fork result and maybe split as well (partially), but it probably won't work for something like fork_clone where we need to check if the struct implClone
.This is also compatible with existing impl, we can put this behind a feature flag if we don't want to expose this feature by default.