Tag:Linghu

  • 004 web assembly Conway game optimization

    Time:2021-12-13

    0 Introduction Video address:www.bilibili.com/video/BV1eg411g7c…Relevant source code:github.com/anonymousGiga/Rust-and-… 1 Description In the implementation of the previous section, we implemented the filled content in rust, and then converted wasm binden to a valid JS string, resulting in unnecessary copies. Because JS code already knows the width and height of the universe, it can directly read the web assembly […]

  • 006 debugging method of web assembly

    Time:2021-12-11

    0 Introduction Video address:www.bilibili.com/video/BV1eg411g7c…Relevant source code:github.com/anonymousGiga/Rust-and-… In the previous section, we tested the previously written code. In this section, we introduce the debugging method. Before we write more code, we hope to have some debugging tools to let us debug bugs in our code. Some specific tools will be introduced later. Next, we mainly introduce […]

  • Rust programming video tutorial (Advanced) – 002 trait

    Time:2021-11-17

    Video address Headline address:https://www.ixigua.com/i677586170644791348…Station B address:https://www.bilibili.com/video/av81202308/ Explanation content 1. Trait is used to define functions shared with other types, similar to interfaces in other languages.(1) Shared behavior can be defined in an abstract way through trait.(2) You can use trait bounds to specify that a generic type is any type that has a specific behavior. […]

  • Rust programming video tutorial (Advanced) – 003_ 2 Adapter

    Time:2021-11-16

    Video address Headline address:https://www.ixigua.com/i677586170644791348…Station B address:https://www.bilibili.com/video/av81202308/ Explanation content 1. Consumer adapterIterator trait has a series of default implementation methods provided by the standard library. Some methods call the next method. These methods that call the next method are called consumption adapters. Examples are as follows: let v1 = vec![1, 2, 3]; let v1_iter = v1.iter(); […]

  • Brush leetcode question 7 with rust

    Time:2021-11-12

    Problem Given a 32-bit signed integer, reverse digits of an integer. Example Example 1:Input: 123Output: 321 Example 2:Input: -123Output: -321 Example 3:Input: 120Output: 21 Note: Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−2^31^,  2^31 ^− 1]. For the purpose of this problem, assume that your […]

  • Rust programming video tutorial (Advanced) – 004_ 5 example of life cycle

    Time:2021-11-10

    Video address Headline address:https://www.ixigua.com/i677586170644791348…Station B address:https://www.bilibili.com/video/av81202308/ Explanation content Combining generic parameters, trait boundaries, and lifecycle use std::fmt::Display; fn longest_with_an_announcement<‘a, T>(x: &’a str, y: &’a str, ann: T) -> &’a str where T: Display { println!(“Announcement! {}”, ann); if x.len() > y.len() { x } else { y } } fn main() { let s1 = […]

  • Rust programming video tutorial (Advanced) – 003_ 3 custom iterator

    Time:2021-11-7

    Video address Headline address:https://www.ixigua.com/i677586170644791348…Station B address:https://www.bilibili.com/video/av81202308/ Explanation content 1. Implement iterator trait to create custom iteratorsexample: struct Counter { count: u32, } impl Counter { fn new() -> Counter { Counter { count: 0 } } } //Implement custom iterators impl Iterator for Counter { type Item = u32; fn next(&mut self) -> Option<Self::Item> { […]

  • Rust programming video tutorial corresponding explanation content – Option

    Time:2021-11-6

    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 1. Option is an enumeration defined by the standard library. enum Option<T> { Some(T), None, } 2. Use examples let some_number = Some(5); let some_string = Some(“a string”); let absent_number: Option<i32> = None; let x: i8 = 5; let y: Option<i8> = Some(5); let […]

  • Rust programming video tutorial (Advanced) – 005_ 1 closure introduction

    Time:2021-11-5

    Video address Headline address:https://www.ixigua.com/i677586170644791348…Station B address:https://www.bilibili.com/video/av81202308/ Explanation content 1. Closures are anonymous functions that can be saved into variables or passed to other functions as parameters. Unlike functions, closures allow you to capture values in the caller’s scope. 2. How closures are usedExample 1: fn main() { let use_closure = || { println!(“This is a […]

  • Rust programming video tutorial (Advanced) – 005_ 2 use closures with generics and FN trait

    Time:2021-11-4

    Video address Headline address:https://www.ixigua.com/i677586170644791348…Station B address:https://www.bilibili.com/video/av81202308/ Explanation content Example: / / implement a cache, process the first incoming value and save it struct Cacher<T> Where t: FN (U32) – > U32 // generics and FN trait { Calculation: T, // T is a closure value: Option<u32>, } impl<T> Cacher<T> where T: Fn(u32) -> u32 { […]

  • Rust programming video tutorial (Advanced) – 006cargo enhancement (release configuration custom build)

    Time:2021-11-3

    Video address Headline address:https://www.ixigua.com/i677586170644791348…Station B address:https://www.bilibili.com/video/av81202308/ Explanation content Publishing configurations are predefined and customizable configurations with different options. They allow programmers to more flexibly control a variety of options for code compilation. Each configuration is independent of each other. Cargo has two main configurations:(1) Dev configuration used when running cargo build; (the generated target file […]

  • Rust programming video tutorial (Advanced) – 008cargo workspace

    Time:2021-11-1

    Video address Headline address:https://www.ixigua.com/i677586170644791348…Station B address:https://www.bilibili.com/video/av81202308/ Explanation content 1. Building large-scale projects will certainly involve. 2. Example 1: (1)mkdir addr (2)cd add(3) Create cargo.toml and add the following contents: [workspace] members = [ “adder”, ] (4) Run in the current directorycargo new adder(5) Run cargo build to build the workspace(6) You can use tree to […]