rust way step 1

install rust

CARGO_HOME  D:\rust\.cargo

RUSTUP_HOME D:\rust\.rustup

[dependencies] ferris-says = "0.2"

vscode 安装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

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" }
            }
        }
    }
}
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!" }
    }
}
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" } },
    }
}

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" }
        }
    }
}

相关推荐

  1. nvm1.1.11

    2024-07-10 06:36:08       34 阅读
  2. 1.下午试题1

    2024-07-10 06:36:08       14 阅读
  3. HTML-1

    2024-07-10 06:36:08       40 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-10 06:36:08       4 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-10 06:36:08       5 阅读
  3. 在Django里面运行非项目文件

    2024-07-10 06:36:08       4 阅读
  4. Python语言-面向对象

    2024-07-10 06:36:08       4 阅读

热门阅读

  1. .gitmodules文件

    2024-07-10 06:36:08       8 阅读
  2. git提交emoji指南

    2024-07-10 06:36:08       7 阅读
  3. 自动化测试的秘诀:Conda包依赖的智能检测之旅

    2024-07-10 06:36:08       13 阅读
  4. 升级之道:精通Conda的自我升级艺术

    2024-07-10 06:36:08       8 阅读
  5. python拆分Excel数据,自动发邮箱

    2024-07-10 06:36:08       9 阅读
  6. 【LeetCode】169. 多数元素

    2024-07-10 06:36:08       9 阅读
  7. Docker基础使用

    2024-07-10 06:36:08       10 阅读
  8. c_各个unsigned int 和 int的取值范围

    2024-07-10 06:36:08       10 阅读
  9. SVG in VSCode: A Comprehensive Guide

    2024-07-10 06:36:08       7 阅读
  10. 缓存新境界:Eureka中服务的分布式缓存实现策略

    2024-07-10 06:36:08       6 阅读
  11. 架构设计(2)云原生架构与实例部署

    2024-07-10 06:36:08       9 阅读
  12. 力扣--滑动窗口最大值

    2024-07-10 06:36:08       10 阅读