Tag:Linghu

  • Rust programming video tutorial (Advanced) — 028_ 2 return closure

    Time:2021-7-22

    Video address Headline address:https://www.ixigua.com/i677586170644791348…Station B address:https://www.bilibili.com/video/av81202308/ Source address GitHub address:https://github.com/anonymousGiga/learn_rus… Explanation content Return closureError example: fn returns_closure() -> Fn(i32) -> i32 { |x| x + 1 } Correct example: fn returns_closure() -> Box<dyn Fn(i32) -> i32> { Box::new(|x| x + 1) } fn main() { let c = returns_closure(); println!(“r = {}”, c(1)); //Equivalent to […]

  • Rust programming video tutorial (Advanced) — 026_ 4 advanced trait4

    Time:2021-7-21

    Video address Headline address:https://www.ixigua.com/i677586170644791348…Station B address:https://www.bilibili.com/video/av81202308/ Source address GitHub address:https://github.com/anonymousGiga/learn_rus… Explanation content 1. The parent trait is used to use the function of a trait in another traitSometimes we may need one trait to use the function of another. In this case, we need to be able to rely on the relevant trait to be […]

  • Rust programming video tutorial (Advanced) — 026_ 3 Advanced trait3

    Time:2021-7-20

    Video address Headline address:https://www.ixigua.com/i677586170644791348…Station B address:https://www.bilibili.com/video/av81202308/ Source address GitHub address:https://github.com/anonymousGiga/learn_rus… Explanation content Fully qualified grammar(1) Methods with the same name trait A{ fn print(&self); } trait B{ fn print(&self); } struct MyType; impl A for MyType{ fn print(&self) { println!(“A print for MyType”); } } impl B for MyType{ fn print(&self) { println!(“B print for […]

  • Rust disable lint warning by property

    Time:2021-7-17

    The compiler provides dead_ Code lint, which will warn unused functions and can be disabled with an attribute.example: fn func1() { println!(“func1”); } #[allow(dead_code)] fn func2() { println!(“func2”); } fn func3() { println!(“func3”); } fn main() { func1(); println!(“Hello, world!”); } Note: there will be a warning if func3 is not used, but there will […]

  • Rust conditional compilation

    Time:2021-7-16

    Conditional compilation can be implemented by two different operators, as follows: CFG attribute: use # [CFG (…)] in attribute position cfg! Macros: using CFG in Boolean expressions!…) Example 1: //Compile only if the target system is Linux #[cfg(target_os = “linux”)] fn are_you_on_linux() { println!(“linux!”) } //Compile only if the target system is not Linux #[cfg(not(target_os […]

  • Rust programming video tutorial (Advanced) — 029_ 2 declaration macro

    Time:2021-7-14

    Video address Headline address:https://www.ixigua.com/i677586170644791348…Station B address:https://www.bilibili.com/video/av81202308/ Source address GitHub address:https://github.com/anonymousGiga/learn_rus… Explanation content Using Marco_ rules! Declaration macro forExample 1: let v = vec![ 1, 2, 3];// vec! It’s Marco_ rules! Declaration macro for Example 2:(1)mkdir learn_marco1(2)cd learn_marco1(3) VIM cargo.toml, edit workspace: [workspace] members = [ “mac”, “main”, ] (4)cargo new mac –lib(5) Edit MAC / […]

  • Brush the second question of leetcode with rust

    Time:2021-7-9

    Problem You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.You may assume the two numbers do not contain any leading zero, except the number 0 itself. […]

  • Rust programming video tutorial corresponding content variable

    Time:2021-7-8

    Video address Headline address:https://www.ixigua.com/i676544267458235648…Station B address:https://www.bilibili.com/video/av78062009?…Netease cloud classroom address:https://study.163.com/course/introduction…. Explanation content const MAX_POINTS1: u32 = 100000; //const fn main() { const MAX_POINTS: u32 = 100000; //const println!(“MAX_POINTS = {}”, MAX_POINTS); // println!(“MAX_POINTS = {}”, MAX_POINTS1); // //let a: u32 = 10; //inmut let mut a: u32 = 10;//mutable println!(“a = {}”, a); let b: String […]

  • Implementation of queue with rust

    Time:2021-7-7

    For the implementation of(https://rustcc.gitbooks.io/rustprimer/cont…The source code is as follows: #[derive(Debug)] struct Queue<T> { qdata: Vec<T>, } impl <T> Queue<T> { fn new() -> Self { Queue{ qdata: Vec::new() } } fn push(&mut self, item: T) { self.qdata.push(item); } fn pop(&mut self) ->Option<T> { let l = self.qdata.len(); if l > 0 { let v = […]

  • Process control: the corresponding content of rust programming video tutorial

    Time:2021-7-3

    Video address Headline address:https://www.ixigua.com/i676544267458235648…Station B address:https://www.bilibili.com/video/av78062009?…Netease cloud classroom address:https://study.163.com/course/introduction…. Explanation content fn main() { //if let y = 1; if y == 1 { println!(“y = 1”); } //if-else if y == 1 { println!(“y = 1”); } else { println!(“y != 1”); } //if – else if – else if y == 0 { […]

  • Rust programming video tutorial corresponding content type

    Time:2021-7-2

    Video address Headline address:https://www.ixigua.com/i676544267458235648…Station B address:https://www.bilibili.com/video/av78062009?…Netease cloud classroom address:https://study.163.com/course/introduction…. Explanation content use std::usize; fn show(arr: [u32; 3]) { for i in &arr { println!(“{}”, i); } } fn main() { //bool let is_ok: bool = true; let is_error = false; println!(“is_ok = {}”, is_ok); println!(“is_error = {}”, is_error); //In particular, the type of trust char […]

  • U8 array to string

    Time:2021-6-29

    Problem description The question comes from a question in the English Forum of trust https://users.rust-lang.org/t/pushing-u8-values-to-a-string/36060 , the error code is as follows: fn main() { let mut signature_string = String::new(); let signature_code = [177,187,102,36,165,137,39, 63,52,197,173,13,168,216,95,3,175,113,213,98,52, 77,175,152,79,188,119,141,52,19,19,53,]; for a in signature_code().iter() { println!(” N: {:x?}”, a); signature_string.push(a); } println!(“the entire array HEX as a single string: […]