Crates.io | asteracea |
lib.rs | asteracea |
version | 0.0.2 |
source | src |
created_at | 2020-10-05 19:58:55.421766 |
updated_at | 2020-10-08 16:57:59.791633 |
description | A web application framework for Rust. Asteracea can be used for client-side and server-side rendering and for statically rendered and deployed sites (and combinations thereof) without specific changes to an app's code. |
homepage | https://github.com/Tamschi/Asteracea/tree/v0.0.2 |
repository | https://github.com/Tamschi/Asteracea |
max_upload_size | |
id | 296409 |
size | 42,151 |
Asteracea is a web application framework aiming to combine the strengths of Angular and React while fully supporting Rust's lifetime model.
Note: Asteracea is experimental software.
While it appears to work well so far, there likely will be breaking changes to the template syntax.
Please use cargo-edit to always add the latest version of this library:
cargo add asteracea
Little boilerplate / Useful defaults
Most generated boilerplate code is adjusted automatically to what is required. For example, the signature of a component's .render
method changes if a Node
is generated.
There is still room for improvement here without sacrificing readability.
Co-location / DRY
Intent shouldn't need to be reiterated in multiple places (split declaration, initialisation and usage).
For now, short form captures nested in the component templates provide a way to centralise some semantics (similarly to React's Hooks but without their control flow limitations).
Robust code
Element names are statically checked against lignin-schema
by default, but other schemata can be defined similarly. Empty elements like <br>
cannot contain children.
Similar checks for attributes and event names are planned.
No default runtime
Asteracea components compile to plain Rust code with (usually) no further dependencies, which helps keep bundles small.
Use lignin-dom
or lignin-html
to transform rendered Node
trees into live user interfaces.
The most simple (Node
-rendering) component can be written like this:
asteracea::component! {
Empty()()
[] // Empty node sequence
}
// Render into a bump allocator:
let mut bump = lignin::bumpalo::Bump::new();
assert!(matches!(
Empty::new().render(&mut bump),
lignin::Node::Multi(&[]) // Empty node sequence
));
If the component body isn't a Node
expression, the component will return ()
by default and won't require a Bump
reference to be rendered.
A different return type can be specified after the render argument list.
asteracea::component! {
Unit(/* ::new arguments */)(/* .render arguments */) /* -> () */
{} // Empty Rust block
}
asteracea::component! {
Offset(base: usize)(offset: usize) -> usize
|pub base: usize = {base}|; // ²
{ self.base + offset }
}
assert_eq!(Unit::new().render(), ());
assert_eq!(Offset::new(2).render(3), 5);
² https://github.com/Tamschi/Asteracea/issues/2
For a relatively complex example, see this parametrised counter:
use asteracea::component;
use std::cell::RefCell;
fn schedule_render() { /* ... */ }
component! {
pub Counter(initial: i32, step: i32)()
|value = RefCell::<i32>::new(initial)|; // shorthand capture
|step: i32 = {step}|; // long form capture, ²
<div
"The current value is: " !{*self.value.borrow()} <br>
<button
!{self.step} // shorthand bump_format call
+"click" {
*self.value.borrow_mut() += self.step;
schedule_render();
}
>
>
}
impl Counter {
pub fn value(&self) -> i32 {
*self.value.borrow()
}
pub fn set_value(&self, value: i32) {
self.value.replace(value);
}
}
² https://github.com/Tamschi/Asteracea/issues/2
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Asteracea strictly follows Semantic Versioning 2.0.0 with the following exceptions:
This includes the Rust version requirement specified above.
Earlier Rust versions may be compatible, but this can change with minor or patch releases.
Which versions are affected by features and patches can be determined from the respective headings in CHANGELOG.md.