用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tomevault-io/skills-registry --skill rust-dioxus命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | rust-dioxus |
| description | | Use when this capability is needed. |
A comprehensive guide to building beautiful, performant, and reactive user interfaces in Rust targeting WASM, Native Desktop, Mobile, and Server-Side Rendering (SSR).
# Install the cargo helper utility
cargo install dioxus-cli
# Initialize a project template
dx new my-app --template fullstack
dx serve
# Cargo.toml
[dependencies]
dioxus = { version = "0.6", features = ["web"] } # or "desktop", "fullstack"
Dioxus components are regular functions annotated with #[component] returning an Element:
use dioxus::prelude::*;
#[component]
pub fn App() -> Element {
rsx! {
div {
class: "app-container",
Header { title: "Dioxus Dashboard" }
MainContent {}
}
}
}
#[component]
fn Header(title: String) -> Element {
rsx! {
header { class: "nav-header", h1 { "{title}" } }
}
}
key attribute when rendering dynamic lists inside loops.rsx! {
ul {
for user in users.read().iter() {
li { key: "{user.id}", "{user.name}" }
}
}
}
Dioxus handles state tracking automatically via thread-safe Signals.
#[component]
fn Counter() -> Element {
let mut count = use_signal(|| 0);
rsx! {
button {
onclick: move |_| count += 1, // Mutates value and triggers re-render
"Count: {count}"
}
}
}
Use use_memo to cache computations and prevent wasteful recalculations when dependencies haven't changed.
let value = use_signal(|| 10);
let doubled = use_memo(move || value() * 2);
Provide and consume structured context globally down the virtual DOM tree without prop-drilling.
#[derive(Clone, Copy)]
struct AppState {
authenticated: Signal<bool>,
}
// Parent Component
use_context_provider(|| AppState {
authenticated: Signal::new(false),
});
// Child Component
let state = use_context::<AppState>();
Use use_resource to run async fetching routines.
let posts = use_resource(move || async move {
reqwest::get("https://api.example.com/posts")
.await?
.json::<Vec<Post>>()
.await
});
match &*posts.read_unchecked() {
None => rsx! { "Loading..." },
Some(Err(e)) => rsx! { "Error: {e}" },
Some(Ok(list)) => rsx! {
for post in list {
p { "{post.title}" }
}
}
}
Define APIs that compile to RPC endpoints automatically.
#[server(GetDatabaseStats)]
pub async fn get_stats() -> Result<Stats, ServerFnError> {
// This code executes purely on the backend server
Ok(db::fetch_stats().await?)
}
Ensure you configure Window preferences elegantly on desktop launches:
fn main() {
dioxus::LaunchBuilder::desktop()
.with_cfg(
dioxus::desktop::Config::default()
.with_window(
dioxus::desktop::WindowBuilder::new()
.with_title("App")
.with_inner_size(dioxus::desktop::LogicalSize::new(1280, 720))
)
)
.launch(App);
}
Keep component logic in pure functions or hooks so behavior can be tested without a browser.
fn format_count(count: i32) -> String {
match count {
0 => "No items".to_string(),
1 => "1 item".to_string(),
n => format!("{n} items"),
}
}
#[test]
fn formats_count() {
assert_eq!(format_count(2), "2 items");
}
rsx!; pass IDs or Arc when appropriate.let filtered = use_memo(move || {
let query = query.read().to_lowercase();
items.read()
.iter()
.filter(|item| item.name.to_lowercase().contains(&query))
.cloned()
.collect::<Vec<_>>()
});
Represent loading, error, and success states explicitly. Do not unwrap in render paths.
#[derive(Clone)]
enum LoadState<T> {
Idle,
Loading,
Loaded(T),
Failed(String),
}
Source: adxptived/Rust-Skills — distributed by TomeVault.