TFT-LCD驱动板信号链路详解:TCON时序与Source/Gate Driver实战排查
2026/10/6 14:46:36
Rust中变量默认不可变,使用let声明。可变变量需添加mut关键字:
let x = 5; // 不可变 let mut y = 10; // 可变 y = 15; // 允许修改常量使用const声明,必须标注类型:
const MAX_POINTS: u32 = 100_000;基本类型包括标量(整型、浮点、布尔、字符)和复合类型(元组、数组):
let tup: (i32, f64, u8) = (500, 6.4, 1); let arr = [1, 2, 3]; // 固定长度数组使用fn定义函数,参数需注明类型:
fn add(a: i32, b: i32) -> i32 { a + b // 无分号表示返回值 }if表达式:
let number = if condition { 5 } else { 6 };循环(loop/while/for):
for element in arr.iter() { println!("{}", element); }Rust核心特性,规则包括:
let y = x转移(移动语义)引用允许借用值而不获取所有权:
let s1 = String::from("hello"); let len = calculate_length(&s1); // 不可变引用定义和使用结构体:
struct User { username: String, email: String, } let user = User { email: String::from("user@example.com"), username: String::from("user123"), };枚举定义:
enum Message { Quit, Move { x: i32, y: i32 }, }模式匹配:
match msg { Message::Quit => println!("Quit"), Message::Move { x, y } => println!("Move to ({}, {})", x, y), }Result类型处理可恢复错误:
let f = File::open("file.txt"); match f { Ok(file) => file, Err(error) => panic!("Problem opening the file: {:?}", error), }使用mod组织代码:
mod front_of_house { pub mod hosting { pub fn add_to_waitlist() {} } } use crate::front_of_house::hosting; hosting::add_to_waitlist();确保引用有效性的标注:
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str { if x.len() > y.len() { x } else { y } }