-
Notifications
You must be signed in to change notification settings - Fork 88
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
Allow deriving protocols with Any #587
base: main
Are you sure you want to change the base?
Conversation
One thing to decide is whether to require the This would mean that:
So this would boil down, would we rather require |
This now also includes 0adc1bb, which is related but not equivalent for associated functions. #[derive(Any, Clone)]
#[rune(item = ::std::env)]
#[rune(functions(Self::is_set))]
struct Var {
name: String,
value: Option<String>,
}
impl Var {
#[function]
fn is_set(&self) -> bool {
self.value.is_some()
}
} |
Also, very much WIP, if you agree overall, I'll add the missing traits. And we'll also need documentation and tests. |
0adc1bb
to
7944dbe
Compare
Thanks! I'm out now! I'll check it out when I get back next week. |
7944dbe
to
ba7e74d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great feature, thank you!
Documentation and tests and I'd consider it done, even if we need to add more protocols later on.
The one nit I have about syntax is that I'd probably prefer the use #[rune_derive(..)]
and #[rune_functions(..)]
over #[rune(protocols(..))
and #[rune(functions(..))]
. I'm not a huge fan of nested attributes.
Regarding naming, what do you say?
whatever you prefer, I don't have a strong feeling there. |
@udoprog what is your opinino on this?
|
Seems fine. For the way it's implemented you should even be able to omit |
currently yes the question was about changing this, i.e. making single ident function names be associated by default and only resolve paths relatively to the module. i.e. "the_fn" would be "Self::the_fn" and "self::the_fn" would be "self::the_fn", i.e. the containing module. Currently it is "Self::the_fn" is "Self::the_fn" and "the_fn" would resolve to "self::the_fn" i.e. the containing module. |
Oh I see. Well, then no. Let them resolve to whatever path they're part of? They're declared within an impl that sees |
ba7e74d
to
877ebf3
Compare
6cc975d
to
a4bb337
Compare
/// fn second(it: Struct) -> usize { | ||
/// it.1 | ||
/// } | ||
/// ``` | ||
pub use rune_macros::Any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@udoprog The docs for the Any
macro are actually not shown. Not sure if that is due to being reexported again at the crate root.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT the only way around that, is moving this reexport in the crate root.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welp, time to move!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what would be your preference? Add the documentation in rune-macros or in rune's lib.rs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the re-export and document it. Otherwise you have a circular dev-dependency for any doc tests that uses rune which rust-analyzer does not like. And all the documentation in one place.
PR looks to be in pretty good shape with a few things that can be done later. Would you be OK with me going over, clean a few things up and merging it? |
Sounds good. IIRC one thing that needs fixing is the |
What is blocking this feature right now? I would be really interested for this functionality. |
Rebasing, cleaning up the PR, and bandwidth. I'll have another stint working on Rune eventually, and then I plan to pick it up again. But if you're interested, please go ahead! |
Usage
fixes #583