跳至主要內容
產品桌面工具TASTECAD圖面檢視TASTEFILES檔案管理TASTEFTP檔案傳輸TASTESSH遠端工作空間TASTEZIP壓縮與解壓縮TASTEWINM檔案管理開發工具TASTECODERust 整合開發環境TASTESTUDIO整合開發與測試環境TASTEETL資料整合(ETL)伺服器TASTEREMOTE遠端桌面伺服器TASTEGEO空間資訊伺服器TASTEMAIL郵件工作空間投資TASTESTOCK股票自動交易桌面應用程式開始使用下載文件購買所有產品
市集
資訊
技術資訊今日開發資訊開發文件程式語言RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWeb 前端框架Next.jsReactVue.js · NuxtSvelteKitAngular伺服器框架Spring BootDjangoFastAPIASP.NET CoreNestJS · Express應用程式與桌面框架TauriFlutterReact NativeElectron演算法演算法基礎核心演算法進階演算法實務演算法
社群專案開發日誌提示詞AI 工具問題作品展示社群指南
合作技術傳授網站建置桌面應用程式建置發布與付款流程銷售合作夥伴聯絡我們
服務遠端桌面安裝包客製
TASTEDEV
產品

桌面工具

TASTECAD再複雜的圖面,也能輕鬆開啟TASTEFILES只挑需要的檔案,最快送達TASTEFTP讓檔案往來,走最俐落的路TASTESSH在你與伺服器之間,築起更穩固的連線TASTEZIP壓得更快,解得更安心TASTEWINM以鍵盤為主、用兩個窗格整理檔案的檔案管理器

開發工具

TASTECODE在一個視窗中完成 Rust 應用程式的編輯、建置、偵錯與測試TASTESTUDIO從編輯到遠端測試,再到經核准的 AI 修正TASTEETL邊看數值,邊搬資料

伺服器

TASTEREMOTE在自己的伺服器上運行的遠端桌面TASTEGEO以 Rust 重新打造相容 GeoServer 的空間資訊伺服器TASTEMAIL把郵件的主導權拿回自己手上

投資

TASTESTOCK何時、做什麼——依你訂下的規則運作的股票自動交易

開始使用

下載所有產品的最新版本文件各產品使用方法購買訂閱與永久授權所有產品一覽全部產品
所有產品
市集資訊
技術

資訊

今日開發資訊語言、框架、GitHub 與 AI 官方發布開發文件語言、框架與演算法指南

程式語言

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

框架

Web 前端框架Next.jsReactVue.js · NuxtSvelteKitAngular
伺服器框架Spring BootDjangoFastAPIASP.NET CoreNestJS · Express
應用程式與桌面框架TauriFlutterReact NativeElectron

演算法

演算法基礎複雜度分析 · 排序 · 搜尋 · 基礎資料結構 · 樹與堆積核心演算法圖形走訪 · 最短路徑與最小生成樹 · 動態規劃 · 貪婪演算法 · 分治法 · 回溯法進階演算法字串演算法 · 數學與數論 · 位元運算 · 線段樹 · 併查集實務演算法程式面試解題策略 · LRU 快取 · 速率限制 · 一致性雜湊
查看全部開發文件
社群
專案探索開發者與作品開發日誌決策與試錯提示詞可重複使用的指令AI 工具問題Claude、Codex、Gemini 的問題與替代做法作品展示已完成的成果社群指南我們如何公開打造
合作
技術傳授用 Rust 與 egui 打造原生應用程式網站建置10 種語言、帳號、文件與下載桌面應用程式建置Rust 與 egui,不用 WebView發布與付款流程簽章、MSI、deb、rpm、AppImage、雜湊銷售合作夥伴推薦即得 30%聯絡我們開發、合作與投資諮詢
服務
遠端桌面用瀏覽器連線你的電腦安裝包客製只裝需要的,設定預先放好
購買
繁
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
登入
登入
TASTEDEV

從小工具到更好的開發。

support@tastedev.net支持 TASTEDEV
產品產品系列購買文件下載市集客戶支援
社群專案開發日誌提示詞AI 工具問題作品展示
政策關於我們隱私權政策服務條款訂閱條款退款政策社群規範
帳戶登入註冊
訪客
今天
昨天
累計瀏覽
公司名稱
GXSOFT
負責人
CHOI YOUNG GU
營業登記號碼
853-44-00368
地址
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
電話
+82-10-4404-1523
電子郵件
whitecalvin@tastedev.net
個人資料保護負責人
CHOI YOUNG GU

© 2026 TASTEDEV產品資訊以經驗證的開發原始碼為準。已發布·持續改進

Rust 文件
Rust
Getting Started with RustSyntax BasicsTypes and DataModules and PackagesErrors and TestingKey Concepts: Ownership, Borrowing, Lifetimes, Traits
討論

Rust 指南 · 3/6

Types and Data

本章目前僅提供英文版。

Rust is statically typed: every value has a type known at compile time, and even numeric types never convert silently. This chapter tours the primitive types, the two kinds of strings, structs and enums, the everyday collections, and Option, Rust's answer to null.

Scalar types

KindTypesNotes
Signed integersi8 i16 i32 i64 i128 isizei32 is the default
Unsigned integersu8 u16 u32 u64 u128 usizeindexes and lengths use usize
Floating pointf32 f64f64 is the default
Booleanbooltrue or false
Charactercharone Unicode scalar value, 4 bytes

Integer overflow panics in debug builds and wraps around by default in release builds. When overflow is a real possibility, say what you mean with checked_add, wrapping_add or saturating_add. Conversions are explicit with as.

fn main() {
    let a: i32 = -42;
    let b: u8 = 255;
    let c = 3.14_f64;
    let ok: bool = true;
    let heart: char = '♥';
    println!("{a} {b} {c} {ok} {heart}");

    println!("{:?}", b.checked_add(1)); // None on overflow
    println!("{}", b.wrapping_add(1)); // 0, wraps around
    println!("{}", b.saturating_add(1)); // 255, clamps at the max

    let n = 300_i32 as u8; // 44, `as` truncates
    let avg = (7 as f64) / 2.0; // 3.5
    println!("{n} {avg}");
}

Compound types: tuples and arrays

A tuple groups a fixed number of values of different types; an array holds a fixed number of values of the same type. For a list that grows, use Vec, covered below.

fn main() {
    let point: (i32, f64, char) = (1, 2.5, 'x');
    let (x, y, z) = point; // destructuring
    println!("{x} {y} {z} / first field {}", point.0);

    let nums = [1, 2, 3, 4, 5];
    let zeros = [0u8; 4]; // four zeros
    let slice = &nums[1..3]; // [2, 3]
    println!("{} {:?} {:?}", nums.len(), zeros, slice);
}

Indexing past the end of an array panics instead of reading random memory. When an index might be out of range, use nums.get(10), which returns an .

對本章有疑問嗎?
上一章Syntax Basics下一章Modules and Packages
Option

String versus &str

There are two main string types. String is an owned, growable, heap-allocated buffer. &str is a borrowed view into UTF-8 text that lives somewhere else; string literals are &'static str. Taking &str as a parameter lets callers pass either kind.

fn greet(name: &str) -> String {
    format!("Hello, {name}")
}

fn main() {
    let literal: &str = "Rust";
    let mut owned = String::from("Hello");
    owned.push_str(", world");
    owned.push('!');

    println!("{}", greet(literal));
    println!("{}", greet(&owned)); // &String coerces to &str

    let part: &str = &owned[0..5]; // "Hello"
    println!("{part}");

    // len() counts bytes; chars().count() counts characters
    println!("{} {}", "héllo".len(), "héllo".chars().count()); // 6 5
}

Strings are UTF-8, so s[0] is not allowed. Use chars() for characters, and keep range slices on character boundaries.

Structs and enums

A struct bundles related data under named fields. Methods live in an impl block: &self means the method only reads, &mut self means it modifies. Functions without self, like new, are associated functions and are called as Rect::new.

#[derive(Debug, Clone, PartialEq)]
struct Rect {
    width: u32,
    height: u32,
}

impl Rect {
    fn new(width: u32, height: u32) -> Self {
        Self { width, height }
    }
    fn area(&self) -> u32 {
        self.width * self.height
    }
    fn scale(&mut self, k: u32) {
        self.width *= k;
        self.height *= k;
    }
}

fn main() {
    let mut r = Rect::new(3, 4);
    println!("area {}", r.area()); // 12
    r.scale(2);
    println!("{r:?}"); // Rect { width: 6, height: 8 }
}

An enum models "exactly one of these", and each variant can carry its own data. Paired with match, the compiler makes sure every variant is handled.

enum Shape {
    Circle { radius: f64 },
    Square(f64),
    Point,
}

fn area(shape: &Shape) -> f64 {
    match shape {
        Shape::Circle { radius } => std::f64::consts::PI * radius * radius,
        Shape::Square(side) => side * side,
        Shape::Point => 0.0,
    }
}

fn main() {
    let shapes = [Shape::Circle { radius: 1.0 }, Shape::Square(2.0), Shape::Point];
    for s in &shapes {
        println!("{:.2}", area(s));
    }
}

Collections and Option

Rust has no null. A value that may be missing has type Option<T>, which is either Some(value) or None. You must deal with both cases before using the value, which rules out null-pointer errors entirely.

use std::collections::HashMap;

fn main() {
    let mut scores: Vec<i32> = Vec::new();
    scores.push(80);
    scores.push(95);
    let total: i32 = scores.iter().sum();
    println!("{scores:?} total {total}");
    println!("{:?}", scores.get(5)); // None

    let text = "the cat the dog the end";
    let mut counts: HashMap<&str, usize> = HashMap::new();
    for word in text.split_whitespace() {
        *counts.entry(word).or_insert(0) += 1;
    }

    match counts.get("the") {
        Some(n) => println!("the: {n} times"), // 3
        None => println!("not found"),
    }
    let birds = counts.get("bird").copied().unwrap_or(0);
    println!("bird: {birds} times"); // 0
}

Vec<T> is a growable array (also built with vec![1, 2, 3]). HashMap<K, V> maps keys to values; its entry API makes "insert or update" a one-liner. Combinators like map, unwrap_or and and_then often replace a full match on Option.

Summary

  • Numeric type names spell out size and signedness; convert explicitly with as.
  • String owns its text, &str borrows it; prefer &str for parameters.
  • Structs hold data plus impl methods; enums express "one of several cases".
  • Vec and HashMap are the workhorse collections, and Option replaces null.

0 則留言

熱門留言由新到舊

登入 · 登入後即可留言。