fission-codes / rust-template

Fission-focused Rust and Rust+Wasm project templates
Apache License 2.0
39 stars 5 forks source link
cargo cargo-generate nix release-please rust template template-generator template-project wasm
rust-template Logo

rust-template

Build Status License-Apache License-MIT Discord

This template repository is Fission's opinionated Rust, Rust web framework, and Rust+WebAssembly (Wasm) project generator, which uses the cargo-generate tool.

These templates provide various features for getting-up and running with Rust or Rust and Wasm, including:

Outline

Project Templates

This repository contains two sub-templates:

Getting Started

First, install cargo-generate via cargo install cargo-generate. More installation options are available here.

The experience running through the experience should look something like this:

cargo-generate Rust Binary Application Screenshot

Generating a Rust-Only Project

The rust template is designed for generating a rust binary or application library.

Note on SSH-Keys: When genearting a project/repository, please be aware that RSA keys used with SHA-1 signatures are no longer supported by GitHub. There is currently an issue in the cargo-generate repository involving an id_rsa default. If you run into an associated error using the template, please specify your private key when generating a project/repository like so:

cargo generate -i ~/.ssh/id_ed25519 https://github.com/fission-codes/rust-template

🔋 Batteries Included

🔋 Batteries Included Web Framework

If you choose to run a webserver with axum (choosing true at the prompt), you'll be given an extensive web framework to work from, heavily influenced by Composing an observable Rust application, among other sources.

Generating a Rust+Wasm Workspace Project

The rust+wasm template is designed for generating a workspace containing both rust-native library or binary code, as well a library for compilation to Wasm and leveraging wasm-pack. We don't currently support any Javascript examples or frameworks that can use Wasm npm package explicitly, but this is on our radar. Additionally, when using the --bin flag you have the option to generate our axum template with all the 🔋's mentioned above.

Generate a project just like before and choose the rust+wasm template:

cargo generate --lib --git https://github.com/fission-codes/rust-template

Note: Currently, wasm-pack does not support building binary crates, so even with the --bin flag specified, a library will still be generated.

🔋 Batteries Included

Generation in an existing project

The generator is also designed for templating within an existing project and prompts with this in mind. To generate in an existing project, run this command in the project root:

  cargo generate --git https://github.com/fission-codes/rust-template --init

When taking this approach, please be aware that some of the generated code, e.g. benches, READMEs, etc., rely on dependencies or contain text that may not be set in or follow the layout of your existing Rust codebase, so please make the appropriate changes where needed.

If the generator detects a conflict, it will not alter your project in any way, failing with an error. We can't cover all the cases when extending an existing project. If you run into problems, open an issue.

Notes for Post-Project Generation

Contributing

:balloon: We're thankful for any feedback and help in improving our template generator! We have a contributing guide to help you get involved. We also adhere to Fission's Code of Conduct.

Pre-commit Hook

This repository recommends using pre-commit for running pre-commit hooks. Please run this before every commit and/or push.

Template References

Thanks

Major shout-outs to the various contributors of this work, including:

License

This project is 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.