02 2024 档案

摘要:function logThis() { console.log(this) } const obj = { logThis, logThis2() { logThis() }, logThis3() { obj.logThis() } } obj.logThis(); obj.logThis2() 阅读全文
posted @ 2024-02-29 22:11 Zhentiw 阅读(3) 评论(0) 推荐(0) 编辑
摘要:Here is how typescript does the same thing export type Data = { projector: { //pwd [key: string]: { // key -> value [key: string]: string, } } } Here 阅读全文
posted @ 2024-02-29 19:54 Zhentiw 阅读(1) 评论(0) 推荐(0) 编辑
摘要:Following code has compile error: #[test] fn main() { let vec0 = vec![22, 44, 66]; let mut vec1 = fill_vec(vec0); assert_eq!(vec1, vec![22, 44, 66, 88 阅读全文
posted @ 2024-02-27 15:37 Zhentiw 阅读(5) 评论(0) 推荐(0) 编辑
摘要:Following code has borrow problem: #[test] fn main() { let vec0 = vec![22, 44, 66]; let vec1 = fill_vec(vec0); assert_eq!(vec0, vec![22, 44, 66]); ass 阅读全文
posted @ 2024-02-27 15:33 Zhentiw 阅读(7) 评论(0) 推荐(0) 编辑
摘要:Define a macro and use it: macro_rules! my_macro { () => { println!("Check out my macro!"); }; } fn main() { my_macro!(); } Notice that you have time 阅读全文
posted @ 2024-02-27 15:23 Zhentiw 阅读(4) 评论(0) 推荐(0) 编辑
摘要:Methods: mod sausage_factory { // private method fn get_secret_recipe() -> String { String::from("Ginger") } // public method pub fn make_sausage() { 阅读全文
posted @ 2024-02-27 14:51 Zhentiw 阅读(5) 评论(0) 推荐(0) 编辑
摘要:enum Message { ChangeColor(u8, u8, u8), Echo(String), Move(Point), Quit, } struct Point { x: u8, y: u8, } struct State { color: (u8, u8, u8), position 阅读全文
posted @ 2024-02-26 23:44 Zhentiw 阅读(4) 评论(0) 推荐(0) 编辑
摘要:Web API, such as setTimeout setInterval which goes into Macrotask Queue; Microtask such as, code after await, Promise, all go to Microtask Queue direc 阅读全文
posted @ 2024-02-26 16:03 Zhentiw 阅读(4) 评论(0) 推荐(0) 编辑
摘要:Code: config.go package projector import ( "fmt" "os" "path" ) type Operation = int const ( Print Operation = iota Add Remove ) type Config struct { A 阅读全文
posted @ 2024-02-26 15:47 Zhentiw 阅读(3) 评论(0) 推荐(0) 编辑
摘要:The TryFrom and try_into() methods are part of the. standard libaray's conversion traits, designed to handle conversions between types in a fallible m 阅读全文
posted @ 2024-02-26 14:54 Zhentiw 阅读(10) 评论(0) 推荐(0) 编辑
摘要:https://doc.rust-lang.org/std/string/struct.String.html#method.trim fn string_slice(arg: &str) { println!("{}", arg); } fn string(arg: String) { print 阅读全文
posted @ 2024-02-26 03:15 Zhentiw 阅读(7) 评论(0) 推荐(0) 编辑
摘要:Structs contain data, but can also have logic. In this exercise we have defined the Package struct and we want to test some logic attached to it. #[de 阅读全文
posted @ 2024-02-26 02:51 Zhentiw 阅读(5) 评论(0) 推荐(0) 编辑
摘要:https://doc.rust-lang.org/stable/book/ch05-01-defining-structs.html#creating-instances-from-other-instances-with-struct-update-syntax Similar to Javas 阅读全文
posted @ 2024-02-26 02:44 Zhentiw 阅读(9) 评论(0) 推荐(0) 编辑
摘要:fn multiply(x: i64, y: u8) -> i64 { return x * (y as i64); } Here we convert u8to i64, which is possible since i64has a wider range than u8; but you c 阅读全文
posted @ 2024-02-24 19:01 Zhentiw 阅读(1) 评论(0) 推荐(0) 编辑
摘要:https://doc.rust-lang.org/book/ch05-01-defining-structs.html struct ColorClassicStruct { red: i32, green: i32, blue: i32 } struct ColorTupleStruct(i32 阅读全文
posted @ 2024-02-23 19:11 Zhentiw 阅读(7) 评论(0) 推荐(0) 编辑
摘要:fn main() { let cat = ("Furry McFurson", 3.5); let (name, age) = cat; println!("{} is {} years old.", name, age); } Example 2: #[test] fn indexing_tup 阅读全文
posted @ 2024-02-23 19:04 Zhentiw 阅读(2) 评论(0) 推荐(0) 编辑
摘要:fn main() { let a = 0..100; if a.len() >= 100 { println!("Wow, that's a big array!"); } else { println!("Meh, I eat arrays like that for breakfast."); 阅读全文
posted @ 2024-02-23 18:57 Zhentiw 阅读(6) 评论(0) 推荐(0) 编辑
摘要:struct Rectangle { width: i32, height: i32 } impl Rectangle { // Only change the test functions themselves pub fn new(width: i32, height: i32) -> Self 阅读全文
posted @ 2024-02-23 18:50 Zhentiw 阅读(19) 评论(0) 推荐(0) 编辑
摘要:pub fn is_even(num: i32) -> bool { num % 2 == 0 } /* This attribute indicates that the following module is a conditional compilation module that shoul 阅读全文
posted @ 2024-02-23 18:46 Zhentiw 阅读(11) 评论(0) 推荐(0) 编辑
摘要:Code has error: fn main() { let answer = square(3); println!("The square of 3 is {}", answer); } fn square(num: i32) -> i32 { num * num; } Error: ⚠️ C 阅读全文
posted @ 2024-02-23 15:39 Zhentiw 阅读(7) 评论(0) 推荐(0) 编辑
摘要:Constants variable always need to be annotated: const NUMBER: i32 = 3; fn main() { println!("Number {}", NUMBER); } 阅读全文
posted @ 2024-02-23 15:02 Zhentiw 阅读(2) 评论(0) 推荐(0) 编辑
摘要:Ref to : https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#shadowing fn main() { let number = "T-H-R-E-E"; // don't change this lin 阅读全文
posted @ 2024-02-23 14:59 Zhentiw 阅读(10) 评论(0) 推荐(0) 编辑
摘要:This lesson shows how to use a Rust loop to run a program infinitely. use std::io; use std::process; fn main() { loop { println!("Please enter a first 阅读全文
posted @ 2024-02-23 14:39 Zhentiw 阅读(3) 评论(0) 推荐(0) 编辑
摘要:In this lesson we'll learn how to exit a program using the std::process module in Rust and it's exit() method. use std::io; use std::process; fn main( 阅读全文
posted @ 2024-02-23 14:38 Zhentiw 阅读(11) 评论(0) 推荐(0) 编辑
摘要:In this lesson we'll explore how to unwrap a Result type using a language feature called Pattern Matching. use std::io; fn main() { let mut first = St 阅读全文
posted @ 2024-02-23 14:33 Zhentiw 阅读(2) 评论(0) 推荐(0) 编辑
摘要: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 阅读(4) 评论(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 阅读(13) 评论(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 阅读(4) 评论(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 阅读(4) 评论(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 阅读(4) 评论(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 阅读(7) 评论(0) 推荐(0) 编辑
摘要:fn get_input() -> &'static str { return "..##....... #...#...#.. .#....#..#. ..#.#...#.# .#...##..#. ..#.##..... .#.#.#....# .#........# #.##...#... # 阅读全文
posted @ 2024-02-20 15:42 Zhentiw 阅读(13) 评论(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 阅读(5) 评论(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 阅读(2) 评论(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 阅读(2) 评论(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 阅读(33) 评论(0) 推荐(0) 编辑
摘要:// interface {} is the same as `any` type in Typscript func add(inputs []int) interface {} { return inputs[0].Float() + inputs[1].Float() } 阅读全文
posted @ 2024-02-19 20:58 Zhentiw 阅读(2) 评论(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 阅读(6) 评论(0) 推荐(0) 编辑
摘要:package main import ( "fmt" "log" "strconv" "strings" ) type Point struct { x int y int } type Line struct { p1 *Point p2 *Point } func getInput() str 阅读全文
posted @ 2024-02-19 15:58 Zhentiw 阅读(8) 评论(0) 推荐(0) 编辑
摘要:Golang has no built-in function(s) to filter an array. This lesson will teach you two different ways to filter. The first is to create a separate arra 阅读全文
posted @ 2024-02-18 04:05 Zhentiw 阅读(15) 评论(0) 推荐(0) 编辑
摘要:There are numerous ways that you can declare and create arrays and slices in Go. This lesson will show you several and I talk about the advantages and 阅读全文
posted @ 2024-02-18 03:58 Zhentiw 阅读(5) 评论(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 阅读(5) 评论(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 阅读(2) 评论(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 阅读(3) 评论(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 阅读(4) 评论(0) 推荐(0) 编辑
摘要:Converts an observable to a promise by subscribing to the observable, and returning a promise that will resolve as soon as the first value arrives fro 阅读全文
posted @ 2024-02-11 22:00 Zhentiw 阅读(132) 评论(0) 推荐(0) 编辑
摘要:Hello World Let's create a simple Go server, first let's setup the server and do hello world // @filename: main.go package main import ( "fmt" "net/ht 阅读全文
posted @ 2024-02-09 15:58 Zhentiw 阅读(7) 评论(0) 推荐(0) 编辑
摘要:Vanilla Go includes Testing A test is a file with suffix_test.go You define functions with prefix Test and with an special signature receiving a *test 阅读全文
posted @ 2024-02-06 22:16 Zhentiw 阅读(4) 评论(0) 推荐(0) 编辑
摘要:So, let's say we have a function to fetch crypto currencies price: package main import ( "fmt" "sync" "project/api" ) func main() { go getCurrencyData 阅读全文
posted @ 2024-02-06 22:03 Zhentiw 阅读(3) 评论(0) 推荐(0) 编辑
摘要:A goroutine is the Go way of suing threads, we open a goroutine just by invoking any function with a go prefix. go functionCall() Goroutines can commu 阅读全文
posted @ 2024-02-06 16:16 Zhentiw 阅读(1) 评论(0) 推荐(0) 编辑
摘要:Go has a special indexing syntax that forms the basis of removing one or more elements from a slice. I will teach you this syntax and show you its var 阅读全文
posted @ 2024-02-06 03:40 Zhentiw 阅读(11) 评论(0) 推荐(0) 编辑
摘要:Panic recovery is a mechanism in Go that allows a program to handle unexpected errors (panics) gracefully. package main import ( "fmt" ) func mayPanic 阅读全文
posted @ 2024-02-06 03:24 Zhentiw 阅读(3) 评论(0) 推荐(0) 编辑
摘要:defermake sure the operation will be executed at the end of a function. func loadChampions() ([]champion, error) { file, err := os.Open("tft_champions 阅读全文
posted @ 2024-02-06 03:22 Zhentiw 阅读(3) 评论(0) 推荐(0) 编辑
摘要:A memory pool, also known as a memory buffer pool, is a method used in software development for managing memory allocation. Instead of allocating and 阅读全文
posted @ 2024-02-05 16:00 Zhentiw 阅读(10) 评论(0) 推荐(0) 编辑
摘要:Covariance - producer - out - function return position - same arrow direction Contravariance - packager - in - function param position - different arr 阅读全文
posted @ 2024-02-01 16:03 Zhentiw 阅读(13) 评论(0) 推荐(0) 编辑

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