Rust
On this page
Get Started with vivi and Rust
This guide will help you to get started to use vivi with Rust. As alternative to setting your project from scratch you can use the vivi rust template.
1. Install rust and cargo
Install instructions can be found here.
2. Generating a new project
Navigate to desired directory and execute the following command:
cargo new hello-vivi3. Add dependencies
First you need to add Slint as dependency to your project, you can do it by executing the following command inside of the root directory of your new created project:
cargo add slint
As next you need to add slint-build as development dependency to your project by executing the following command:
cargo add slint-build --dev
As last you need also add vivi-ui as development dependency. You can do it by executing the following command:
cargo add vivi_ui --dev4. Add a Slint file to your project
Add a new file to your project with name index.slint and add the following content to the file:
import { MagicWindow, FilledButton } from "@vivi/magic.slint";
export component AppWindow inherits MagicWindow {
preferred-width: 600px;
preferred-height: 400px;
title: "Hello vivi";
FilledButton {
text: "Click me";
}
}5. Add a build script to your project
At the root directory of your project create a file named build.rs with the following content:
fn main() {
slint_build::compile(
"index.slint",
slint_build::CompilerConfiguration::new()
.with_library_paths(vivi_ui::import_paths()),
).unwrap();
}
If this code is executed it compiles the content of the index.slint file to rust and it also includes the vivi components in your
project.
After the file is created the build script needs to be added to the Cargo.toml file.
[package]
# ...
build = "build.rs"6. Update the content of main.rs
Replace the content of main.rs of your project with the following content:
use std::error::Error;
slint::include_modules!();
fn main() -> Result<(), Box<dyn Error>> {
AppWindow::new()?.run()
}
7. Start the application
After all previous steps is finished the application can started by executing the following command in the root directory of the project:
cargo run