Skip to content

bushrat011899/trunk_inline_rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Trunk In-Line Rust

A plugin for Trunk that allows in-line Rust scripts declared using RFC 3424.

Disclaimer

This is just a proof of concept and is riddled with bugs and untested edge cases. Please don't actually use this!

Installation

  • Compile this project using cargo build and place the executable wherever is desirable.
  • Add a post-build hook launching the executable to your Trunk.toml file.
[[hooks]]
stage = "post_build"
command = "trunk_inline_rust"
  • Add a <script type="rust"> element to your HTML document and start writing Rust!
<script type="rust">
    //! ```cargo
    //! [dependencies]
    //! wasm-bindgen = "0.2.92"
    //! ```

    use wasm_bindgen::prelude::*;

    #[wasm_bindgen]
    extern "C" {
        fn alert(s: &str);
    }

    #[wasm_bindgen(start)]
    fn run() {
        alert("Hello World!");
    }
</script>

Features

Scoped Cargo.toml

Each script block has access to declaring its own Cargo.toml using RFC 3424 syntax. No dependencies are included by default, so wasm-bindgen is recommended!

Published Public Members

Any elements marked as pub within a script block will be made available on the Window context, allowing for immediate use in the rest of the document:

<script type="rust">
    //! ```cargo
    //! [dependencies]
    //! wasm-bindgen = "0.2.92"
    //! ```
    use wasm_bindgen::prelude::*;

    #[wasm_bindgen]
    extern "C" {
        fn alert(s: &str);
    }

    #[wasm_bindgen]
    pub fn rusty_alert(input: &str) {
        alert(format!("Rusty Alert: {}", input).as_str());
    }
</script>

<button onclick="rusty_alert('Clicked!')">Click me</button>

About

A plugin for Trunk that allows in-line Rust scripts.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages