Asteracea

Lib.rs Crates.io Docs.rs

Rust 1.45.0 Build Status Crates.io - License

GitHub open issues open pull requests crev reviews

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.

Installation

Please use cargo-edit to always add the latest version of this library:

cmd cargo add asteracea

Design goals

Examples

Empty component

The most simple (Node-rendering) component can be written like this:

```rust 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 )); ```

Unit component

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.

```rust 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 } }

asserteq!(Unit::new().render(), ()); asserteq!(Offset::new(2).render(3), 5); ```

² https://github.com/Tamschi/Asteracea/issues/2

Counter component

For a relatively complex example, see this parametrised counter:

```rust use asteracea::component; use std::cell::RefCell;

fn schedule_render() { /* ... */ }

component! { pub Counter(initial: i32, step: i32)()

|value = RefCell::::new(initial)|; // shorthand capture |step: i32 = {step}|; // long form capture, ²

<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

License

Licensed under either of

at your option.

Contribution

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.

Code of Conduct

Changelog

Planned features

Versioning

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.