Egui template
Rust 100%

README.md

Egui template #

This is a small egui template for cargo-generate. Some batteries included, namely:

  • subsecond for hot-patching
  • egui_async (with tokio)
  • Other essentials, such as tracing and anyhow (as color-eyre)

Installation #

By itself, this repo is not buildable. Instead, use cargo-generate to initialize your project with it. Make sure you have cargo-generate installed first.

# Install with cargo, or see if your package manager offers cargo-generate directly
# More info at https://cargo-generate.github.io/cargo-generate/installation.html
# Use `cargo binstall` instead (if you have it installed) to get pre-built binaries
cargo install cargo-generate

Then, initialize the project with the following:

cargo generate https://tangled.org/metaflame.dev/egui-template

Note: if cargo-generate is failing to instantiate the template from the Tangled repo, make sure your cargo-generate installation is up to date, or try cloning the repo to your machine & use cargo-generate with a local path. (In the latter case, avoid creating build artifacts in the cloned repo, as that can make the process super slow!)

Favorite #

If you'd like, you can favorite this template to avoid typing out the whole URL every time. Create (or edit) $CARGO_HOME/cargo-generate.toml (CARGO_HOME is usually ~/.cargo), then add the following:

[favorites.egui_template]
description = "An egui template with subsecond and egui-async"
git = "https://tangled.org/metaflame.dev/egui-template"

You may then initialize your project with a shorter command:

cargo generate egui_template

Build instructions #

With hot-patching #

To run this egui app with hot-patching enabled, first make sure you have the Dioxus CLI installed:

# You may use `cargo binstall` instead
cargo install dioxus-cli

Then, run the following:

dx serve --hot-patch

Building in release mode will turn subsecond calls into no-ops. Subsecond also currently doesn't work for binaries with a backing library, so all hot-patchable code must be in the binary crate.

Refer to subsecond docs for more info.

Without hot-patching #

Subsecond calls behave as pass-through when the program runs without dx serve (and should get completely optimized away in release mode), so a standard cargo run works just as well.

Tracing config #

To see tracing logs, set the RUST_LOG env var before running the app. This can be done in-line with the run command, e.g. RUST_LOG=info cargo run, or RUST_LOG=trace dx serve --hot-patch. This behavior is implemented by tracing-subscriber, see its docs for details, or adjust the default behavior in setup_env_tracing() in main.rs as needed.

The default is set to INFO (i.e. ERROR, WARN, and INFO logs are shown).