rust way step 1

install rust

CARGO_HOME D:\rust\.cargo

RUSTUP_HOME D:\rust\.rustup

[dependencies] ferris-says = "0.2"

vscode 安装rust 插件

rust 复制代码
use ferris_says::say; // from the previous step
use std::io::{stdout, BufWriter};

fn main() {
    let stdout = stdout();
    let message = String::from("Hello fellow Rustaceans!");
    let width = message.chars().count();

    let mut writer = BufWriter::new(stdout.lock());
    say(message.as_bytes(), width, &mut writer).unwrap();
}

###############################

rust cargo镜像配置 config.toml

[source.crates-io]

replace-with = 'ustc'

[source.ustc]

registry = "git://mirrors.ustc.edu.cn/crates.io-index"

cargo install dioxus-cli

dx new

cd my_project

dx serve

realse

cargo build --bin hellui --release

rust 复制代码
use dioxus::prelude::*;

fn main() {
    launch(app);
}

fn app() -> Element {
    rsx! {
        h1 { "Hello, Dioxus 0.5!" }
        h1 { "Hello, Dioxus 0.5!" }
        h1 { "Hello, Dioxus 0.5!" }
        div { "Hello, world!" }
        div { "Hello, world!" }
        div {
            class: "container",
            h1 {
                "标题",
            }
            p {
                style: "color: blue;",
                "这是一行介绍,字体是蓝色的"
            }
            a {
                href: "https://dioxuslabs.com/",
                "一个跳转到 Dioxus 官网的链接"
            }
            ul {
                li { "列表 - 1" }
                li { "列表 - 2" }
                li { "列表 - 3" }
            }
        }
    }
}
rust 复制代码
use dioxus::prelude::*;

fn main() {
    LaunchBuilder::new()
        .with_cfg(
            dioxus::desktop::Config::new().with_custom_index(
                r#"
<!DOCTYPE html>
<html>
  <head>
    <title>Dioxus app</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <style>body { background-color: olive; }</style>
  </head>
  <body>
    <h1>External HTML</h1>
    <div id="main">dfgdfg</div>
  </body>
</html>
        "#
                .into(),
            ),
        )
        .launch(app);
}

fn app() -> Element {
    rsx! {
        h1 { "Custom HTML!" }
    }
}
rust 复制代码
use dioxus::prelude::*;

fn main() {
    launch(app);
}

fn app() -> Element {
    // You can create as many eval instances as you want
    let mut eval = eval(
        r#"
        // You can send messages from JavaScript to Rust with the dioxus.send function
        dioxus.send("Hi from JS!");
        // You can receive messages from Rust to JavaScript with the dioxus.recv function
        let msg = await dioxus.recv();
        console.log(msg);
        "#,
    );

    // You can send messages to JavaScript with the send method
    eval.send("Hi from Rust1!".into()).unwrap();

    let future = use_resource(move || {
        to_owned![eval];
        async move {
            // You can receive any message from JavaScript with the recv method
            eval.recv().await.unwrap()
        }
    });

    match future.read_unchecked().as_ref() {
        Some(v) => rsx! { p { "{v}" } },
        _ => rsx! { p { "hello" } },
    }
}
rust 复制代码
use dioxus::prelude::*;

fn main() {
    launch(app);
}


/* 

pub fn app() -> Element {
    rsx! {
        p {
            b { "Dioxus Labs" }
            " An Open Source project dedicated to making Rust UI wonderful."
        }

        button {
            // attributes / listeners
            // children
            "Hello, World!"
        }

        div { "Hello, world!" } 

        p {
            b { "Dioxus Labs" }
            " An Open Source project dedicated to making Rust UI wonderful."
        }
    }
}
*/
/* 
pub fn app() -> Element {
    let mut name = use_signal(|| "bob".to_string());

    rsx! {
        input {
            // we tell the component what to render
            value: "{name}",
            // and what to do when the value changes
            oninput: move |event| name.set(event.value())
        }
    }
}*/


pub fn app() -> Element {
    rsx! {
        form { onsubmit: move |event| { println!("Submitted! {event:?}") },
            input { name: "name" }
            input { name: "age" }
            input { name: "date" }
            input { r#type: "submit" }
        }
    }
}
相关推荐
蜡笔小新星7 分钟前
Python Kivy库学习路线
开发语言·网络·经验分享·python·学习
凯子坚持 c7 分钟前
C语言复习概要(三)
c语言·开发语言
coderWangbuer15 分钟前
基于springboot的高校招生系统(含源码+sql+视频导入教程+文档+PPT)
spring boot·后端·sql
无限大.19 分钟前
c语言200例 067
java·c语言·开发语言
余炜yw20 分钟前
【Java序列化器】Java 中常用序列化器的探索与实践
java·开发语言
攸攸太上21 分钟前
JMeter学习
java·后端·学习·jmeter·微服务
篝火悟者22 分钟前
问题-python-运行报错-SyntaxError: Non-UTF-8 code starting with ‘\xd5‘ in file 汉字编码问题
开发语言·python
Kenny.志24 分钟前
2、Spring Boot 3.x 集成 Feign
java·spring boot·后端
Death20024 分钟前
Qt 中的 QListWidget、QTreeWidget 和 QTableWidget:简化的数据展示控件
c语言·开发语言·c++·qt·c#
六点半88826 分钟前
【C++】速通涉及 “vector” 的经典OJ编程题
开发语言·c++·算法·青少年编程·推荐算法