#tree #vdom #no-std

no-std lignin

A virtual DOM structure, primarily for web use

9 releases

0.1.0 Jun 1, 2021
0.0.8 Jun 1, 2021
0.0.7 Apr 25, 2021
0.0.5 Jan 30, 2021
0.0.1 Oct 2, 2020

#496 in Data structures

Download history 27/week @ 2024-01-08 80/week @ 2024-01-15 6/week @ 2024-02-19 64/week @ 2024-02-26 9/week @ 2024-03-04

79 downloads per month
Used in 4 crates

MIT/Apache

140KB
2K SLoC

lignin

Lib.rs Crates.io Docs.rs

Rust 1.46 CI Crates.io - License

GitHub open issues open pull requests crev reviews

A lightweight but featureful virtual DOM library, primarily for web use.

no_std and no dependencies without the "callbacks" feature.

Installation

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

cargo add lignin && cargo add -D lignin --features callbacks

Some type constraints are more strict with the "callbacks" feature enabled, so make sure to always check this way!

When writing a renderer that supports callbacks, instead use

cargo add lignin --features callbacks

to always enable the feature.

Features

"callbacks"

Enables DOM callback support. Off by default. Requires std.

Apps or components can be written against the callback API without enabling this feature, in which case those code paths can be erased at compile-time.

Example

use lignin::{Node, Element, ElementCreationOptions};

// Please bring your own allocator where necessary.
let _ = &Node::HtmlElement {
  element: &Element {
    name: "DIV", // Use all-caps for more efficient DOM interactions.¹
    creation_options: ElementCreationOptions::new(), // `const fn` builder and getter/setter patterns for extensible interfaces.
    attributes: &[],
    content: Node::Multi(&[
      "Hello! ".into(), // Some convenience included.
      Node::Comment {
        comment: "--> Be mindful of HTML pitfalls. <!--", // Renderers must validate.
        dom_binding: None,
      }
    ]),
    event_bindings: &[], // Strongly typed using `web-sys`.
  },
  dom_binding: None, // For JS interop.
}
.prefer_thread_safe(); // Thread-safety can be inferred from bindings!

¹ See Element.tagName (MDN). This avoids case-insensitive comparisons.

Implementation Contract

There are a few ecosystem compatibility rules that aren't covered by Rust's type system or the unsafe keyword. Please see the main module documentation for more information.

Prior Art

  • Dodrio, which didn't quite satisfy my requirements but generally inspired this approach.

Thanks

To Dronaroid for finding a great name for this library, @platy for criticism and pushing me towards a better implementation, and everyone on the Rust Programming Language Community Server discord who answered my questions that came up during the rewrite.

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

Versioning

lignin strictly follows Semantic Versioning 2.0.0 with the following exceptions:

  • The minor version will not reset to 0 on major version changes (except for v1).
    Consider it the global feature level.
  • The patch version will not reset to 0 on major or minor version changes (except for v0.1 and v1).
    Consider it the global patch level.

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.

Dependencies

~0–2.1MB
~41K SLoC