随笔分类 -  Rust

摘要:This lesson discusses how to improve error handling by configuring custom error messages using the expect() function. use std::io; fn main() { let mut 阅读全文
posted @ 2024-02-23 14:29 Zhentiw 阅读(5) 评论(0) 推荐(0) 编辑
摘要:use std::path::PathBuf; use clap::Parser; #[derive(Parser, Debug)] #[clap()] pub struct Opts { pub args: Vec<String>, #[clap(short = 'c', long = "conf 阅读全文
posted @ 2024-02-21 15:51 Zhentiw 阅读(14) 评论(0) 推荐(0) 编辑
摘要:In this lesson you'll learn about Vec<T>, or Vectors. Vectors are like Arrays, a collection of values of the same type, but as opposed to Arrays, Vect 阅读全文
posted @ 2024-02-20 22:36 Zhentiw 阅读(5) 评论(0) 推荐(0) 编辑
摘要:In this lesson we take a look at Arrays and the different ways of creating them. Arrays in Rust are collections of values of the same type that cannot 阅读全文
posted @ 2024-02-20 22:32 Zhentiw 阅读(5) 评论(0) 推荐(0) 编辑
摘要:Learn how to create references in Rust using the borrow-operator & and when they are useful. For a more thorough explanation of references and their c 阅读全文
posted @ 2024-02-20 22:29 Zhentiw 阅读(5) 评论(0) 推荐(0) 编辑
摘要:Everything in Rust has a type. Even functions that don't seem to return anything. In such and similar cases, we're dealing with a Unit Type. Learn abo 阅读全文
posted @ 2024-02-20 22:15 Zhentiw 阅读(8) 评论(0) 推荐(0) 编辑
摘要:fn get_input() -> &'static str { return "..##....... #...#...#.. .#....#..#. ..#.#...#.# .#...##..#. ..#.##..... .#.#.#....# .#........# #.##...#... # 阅读全文
posted @ 2024-02-20 15:42 Zhentiw 阅读(14) 评论(0) 推荐(0) 编辑
摘要:Learn how to represent multiple values of different type using a single type by leveraging the power of tuples in Rust. #[allow(warnings)] fn main() { 阅读全文
posted @ 2024-02-20 02:32 Zhentiw 阅读(6) 评论(0) 推荐(0) 编辑
摘要:In this lesson we take a look at Floating-Point values and the f32 and f64 types. We'll also look at the different ways of defining and creating value 阅读全文
posted @ 2024-02-20 02:20 Zhentiw 阅读(3) 评论(0) 推荐(0) 编辑
摘要:This lesson talks about Integer types in Rust and that there are unsigned and signed integers. It also explains how every the type names are composed 阅读全文
posted @ 2024-02-19 21:25 Zhentiw 阅读(4) 评论(0) 推荐(0) 编辑
摘要:This lesson explains Type Inference in Rust and how it allows the compiler to figure out by itself, what type variables have when they get their value 阅读全文
posted @ 2024-02-19 21:17 Zhentiw 阅读(35) 评论(0) 推荐(0) 编辑
摘要:use anyhow::{Result, anyhow}; use std::str::FromStr; fn get_input() -> &'static str { return "0,9 -> 5,9 8,0 -> 0,8 9,4 -> 3,4 2,2 -> 2,1 7,0 -> 7,4 6 阅读全文
posted @ 2024-02-19 16:00 Zhentiw 阅读(8) 评论(0) 推荐(0) 编辑
摘要:In Rust, the exclamation mark (!) after a name indicates that it is a macro rather than a function. Macros and functions in Rust are called differentl 阅读全文
posted @ 2024-02-15 16:11 Zhentiw 阅读(6) 评论(0) 推荐(0) 编辑
摘要:We can use Reusltenum to do error handling type Result<V, E> { Err(E), Ok(V) } Example: // (): empty // uszie: just return a integre as error for demo 阅读全文
posted @ 2024-02-15 16:09 Zhentiw 阅读(3) 评论(0) 推荐(0) 编辑
摘要:pub enum Option2<T> { None, Some(T) } /** impl is similar to typescript a class with is_some method */ impl<T> Option2<T> { pub fn is_some(&self) -> b 阅读全文
posted @ 2024-02-13 16:04 Zhentiw 阅读(4) 评论(0) 推荐(0) 编辑
摘要:Go Enum package main type GoEnum = int const ( Foo GoEnum = iota Bar Baz ) func main() { } Typescript Enum enum TsEnum { Foo, Bar, Baz } Rust Enum enu 阅读全文
posted @ 2024-02-12 16:04 Zhentiw 阅读(5) 评论(0) 推荐(0) 编辑
摘要:Three rules: There can only be one value owner There can be unlimited immutable borrows (reference) with no mutable references There can be only one m 阅读全文
posted @ 2023-05-29 14:42 Zhentiw 阅读(34) 评论(0) 推荐(0) 编辑
摘要:`Option` and `Result` are two very central enums in Rust, and they are used for error handling and for representing the absence of a value. Here is a 阅读全文
posted @ 2023-05-24 13:57 Zhentiw 阅读(73) 评论(0) 推荐(0) 编辑
摘要:Typescript: import fs from "fs"; const fileName = process.argv[2]; if (fileName) { fs.readFileSync(fileName) .toString() .split("\n") .map((num) => pa 阅读全文
posted @ 2023-05-24 13:52 Zhentiw 阅读(14) 评论(0) 推荐(0) 编辑
摘要:Typescript: function practice(nums: number[], index: number): number { return (nums[index] ?? index) * 5 } In Rust: fn practice(nums: Vec<usize>, inde 阅读全文
posted @ 2023-05-24 01:24 Zhentiw 阅读(7) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示