Comments (11)
That need to be addressed for sure. I've had the idea to add a syntax like this:
let widgets = view_output!(model, root);
Or we could use the function signature to figure out the names, but then still something like this would be necessary to be 100% correct:
let widgets = view_output!(model);
from relm4.
I think there isn't any reason to explicitly specify the root widget, if we can just infer it from function parameters. The second option seems fine, and it would allow for arbitrary variable names for the model.
from relm4.
I wonder if we could reduce the amound of boilerplate by stripping out the type info from the function parameters,
so this:
fn init_parts(
counter: Self::InitParams,
root: &Self::Root,
input: &mut Sender<Self::Input>,
_output: &mut Sender<Self::Output>,
) -> ComponentParts<Self, Self::Widgets> {
let model = AppModel { counter };
let widgets = view_output!();
ComponentParts { model, widgets }
}
turns into this:
init_parts! (counter, root, input, _output) {
let model = AppModel { counter };
let widgets = view_output!();
ComponentParts { model, widgets }
}
This is not very rusty, but it looks nicer.
from relm4.
Oh, I see, you've been suggesting the same idea in #99. So what do you think now?
from relm4.
I think, Rust will actually prevent you from using this syntax. It's weird but everything that isn't the direct input of a macro must be somewhat valid syntax. But in any case you're right and I will experiment with solutions to reduce the boilerplate.
I think the types could be reduces, too, if everything that isn't explicitly declared defaults to ()
unless it's something important like Widgets
.
from relm4.
I did get a syntax similar to this to work with macro_rules in my original ccs prototype.
from relm4.
Rust permits it as long as the user provides ident
arguments
$(#[$attr4:meta])*
fn init(
$argsv:ident: $args:ty,
$rootv:ident,
$inputv:ident,
$outputv:ident
) $init_view:block
from relm4.
I had a similar syntax planned for the menu macro but it didn't work. Rustc doesn't like something like macro!(param) { other code }
, even if it's part of an attribute proc-macro.
The solution with fn
could work, though. Yet I still have to test because, macro_rules!
and proc macros are quite different.
from relm4.
We will have a problem with custom syntax and macros in Rust, it seems. Rust only likes custom syntax once you have at least an outer macro! { input }
to put everything into.
/// Custom syntax NOT allowed
#[test]
struct Test(Custom) {
test: u8,
}
/// Custom syntax allowed
test! {
struct Test(Custom) {
test: u8,
}
}
This mean that attribute macros like #[component]
don't allow custom syntax on their own. Yet once we use a normal proc-macro we might loose support for some tooling including cargo fmt if I'm not mistaken. Also, it's usually kind of nice that Rust catches invalid syntax in the trait impl before the macro has to do anything.
TL:DR we can't use custom syntax in attribute macros directly and it would be nice to keep the macro as attribute macro (to keep the code as natural as possible).
However, what we can do is to use valid Rust syntax for our advantage.
For example, we can do something like this:
// Initialize the UI.
#[args(params, root, input, output)]
fn init_parts() {
...
}
It'd definitely support cargo fmt and looks more Rust-ish, I think.
from relm4.
#[args(params, root, input, output)]
sounds like a good idea if it can work better with IDEs.
from relm4.
Should be fixed now. The macro looks the function parameters and the returned model to figure out the name of the model and to root.
from relm4.
Related Issues (20)
- Add option to not capture panics HOT 6
- Spinner doesn't spin in async app HOT 1
- Consider making `set_global_css` a method
- `if let` support in `view!` macro
- Documentation: Keyboard Events HOT 2
- `transient_for` errors in child component HOT 2
- Missing Trait Implementations for `FlowBox` and Potential Conflicts HOT 2
- Resizeable and expandable columns with TypedColumnView HOT 2
- Replace `this` with `model` in factory
- Support `match` at the top root of the widget
- Make #[local_ref] support expressions
- Just tested, weird behavior HOT 1
- OpenDialog : how to select file in root of disk HOT 1
- Add `extend` method for `FactoryVecDeque`
- Add option to disable RelmAction
- GLib-GIO-CRITICAL **: 23:02:38.707: This application can not open files. HOT 1
- Support for `libadwaita::ToolbarView`? HOT 3
- ProgressBar did not show up as expected. HOT 4
- [email protected] depends still on [email protected] HOT 1
- gtk::MessageDialog is deprecated in favor of gtk::AlertDialog HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from relm4.