03 2024 档案
摘要:Intro to Array.prototype.with(index, value) const ages = [10, 15, 20, 25]; const newAges = ages.with(1, 16); console.log(newAges); // [10, 16, 20, 25]
阅读全文
摘要:Example 1: trait AppendBar { fn append_bar(self) -> Self; } impl AppendBar for String { fn append_bar(mut self) -> Self { self.push_str("Bar"); return
阅读全文
摘要:Example 1: fn main() { let mut shopping_list: Vec<&str> = Vec::new(); shopping_list.push("milk"); } Example 2: struct Wrapper<T> { value: T, } impl<T>
阅读全文
摘要:A baisc iter: #[test] fn main() { let my_fav_fruits = vec!["banana", "custard apple", "avocado", "peach", "raspberry"]; let mut my_iterable_fav_fruits
阅读全文
摘要:function thankYouTag(arrayOfStrings,firstExpression, secondExpression, ...) { console.log( arrayOfStrings, // ["This is the first one ", " This is ano
阅读全文
摘要:Symbol.for("key") Checks if a symbol with the key "key" already exists in the globals symbol registry. If yes, it returns the existing symbol, otherwi
阅读全文
摘要:Difference betwen require and import require can be called conditionally, while the import statement cannot import statements are hoisted, but require
阅读全文
摘要:Generator can run with for .. of and ..., which will only emit yield values For example: function* count() { yield 1; yield 2; return 3; } for (const
阅读全文
摘要:Create a new User instance would create a new login function in memory each time? class User { constructor(username) { this.username = username; } log
阅读全文
摘要:use std::sync::mpsc; use std::thread; use std::time::Duration; fn main() { let (tx, rx) = mpsc::channel(); thread::spawn(move || { let vals = vec![ St
阅读全文
摘要:A channel has two halves: a transmitter and a receiver. The transmitter half is the upstream location where you put rubber ducks into the river, and t
阅读全文
摘要:Arc<T> is a type like Rc<T> that is safe to use in concurrent situations. The a stands for atomic, meaning it’s an atomically reference counted type.
阅读全文
摘要:We ofter use movewith closures passed to thread::spawnbecase the closure will then take ownership of the values it uses from the environment, thus tra
阅读全文
摘要:Code from previous blog: use std::thread; use std::time::Duration; fn main() { thread::spawn(|| { for i in 1..10 { println!("hi number {} from the spa
阅读全文
摘要:We use spawnto create a new thread: use std::thread; use std::time::Duration; fn main() { thread::spawn(|| { for i in 1..10 { println!("hi number {} f
阅读全文
摘要:https://doc.rust-lang.org/std/keyword.ref.html struct Point { x: i32, y: i32, } fn main() { let y: Option<Point> = Some(Point { x: 100, y: 200 }); mat
阅读全文
摘要:https://doc.rust-lang.org/rust-by-example/flow_control/if_let.htmlhttps://doc.rust-lang.org/rust-by-example/flow_control/while_let.html If let: #[test
阅读全文
摘要:// Using catch-all error types like `Box<dyn error::Error>` isn't recommended // for library code, where callers might want to make decisions based on
阅读全文
摘要:use std::error; use std::fmt; use std::num::ParseIntError; fn main() -> Result<(), Box<dyn error::Error>> { let pretend_user_input = "42"; let x: i64
阅读全文
摘要:#[derive(PartialEq, Debug)] enum CreationError { Negative, Zero, } #[derive(PartialEq, Debug)] struct PositiveNonzeroInteger(u64); impl PositiveNonzer
阅读全文
摘要:use std::num::ParseIntError; fn main() -> Result<(), ParseIntError> { let mut token = 100; let pretend_user_input = "8"; let cost = total_cost(pretend
阅读全文
摘要:pub fn generate_nametag_text(name: String) -> Result<String, String> { if name.is_empty() { // Empty names aren't allowed. Err(String::from("`name` wa
阅读全文