Tag:ownership

  • Trust iterator

    Time:2022-6-21

    In trust, the for loop is convenient to write because it is a syntax sugar in most casesIt’s easy to write code like Python list_ = [1, 2, 3, 4, 5] for item in list_: print(item) This is true in trust: let mut vector = vec![1, 2, 3, 4, 5]; for item in vector { […]

  • Understand rust’s border checker

    Time:2022-1-7

    Original link:Understanding the Rust borrow checkerThe day of first taste of rust has finally arrived, and you write down a few lines with great expectationRustCode, and then enter it on the command linecargo runCommand, waiting to be compiled. I’ve heard of it before,RustIt is a language that can run as long as the compilation can […]

  • How does NFT play? Why does cross attract much attention? (upper)

    Time:2021-12-25

    In 2020, in addition to defi, which has been popular for more than half a year, NFT is the brightest in the market. 2021 is the first year of NFT. In this issue, we will explain NFT in detail in the form of two articles. This paper introduces some necessary knowledge of NFT to help […]

  • Rust’s basic notes on ownership

    Time:2021-12-7

    Write in front Ownership system is the most unique and attractive feature of rust. Rust also relies on this feature to achieve his biggest goal: memory security. All rust developers should understand it in detail.What a strong flavor of translation. Indeed, I mainly rely on official documents (written clearly and in detail) to learn rust. […]

  • On references and borrowing of rust basic notes

    Time:2021-12-6

    Borrowing Let’s start with a code: fn foo(v1: Vec<i32>, v2: Vec<i32>) -> (Vec<i32>, Vec<i32>, i32) { // do stuff with v1 and v2 // hand back ownership, and the result of our function (v1, v2, 42) } let v1=vec![1, 2, 3]; let v2=vec![1, 2, 3]; let (v1, v2, answer) =foo(v1, v2); If you have to […]

  • Rust basic notes: closures

    Time:2021-12-2

    grammar Closure looks like this: let plus_one = |x: i32| x + 1; assert_eq!(2, plus_one(1)); First create a binding plus_ One, and then assign it to a closure. The body is an expression. Note that {} is also an expression. It can also be written like this: let plus_two = |x| { let mut result: […]

  • Variable ownership type

    Time:2021-11-19

    It’s actually a question and answer post. The official answers too many questions and doesn’t want to answer them,Look at the source code of the add method of string. See a piece of code that is a little confused. Record it. The following is a simple example #[derive(Debug)] struct B { name:String } impl B […]

  • Rust programming video tutorial (Advanced) – 005_ 3 values in closure capture environment

    Time:2021-11-11

    Video address Headline address:https://www.ixigua.com/i677586170644791348…Station B address:https://www.bilibili.com/video/av81202308/ Explanation content 1. Closures capture values in the environment fn main() { let x = 4; let equal_ to_ x = |z| z == x; // Capture values in the environment let y = 4; assert!(equal_to_x(y)); } Closures can capture their environment in three ways. They correspond to the […]

  • Rust programming video tutorial (Advanced) – 018_ 1 Introduction to mutex

    Time:2021-10-5

    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 channel in any programming language is similar to the single ownership method, that is, once a value is transmitted to the channel, the (sender) will no longer be able to use the value; Shared memory is similar to multi ownership, that […]

  • A 30 minute introduction to rust

    Time:2021-10-3

    I recently submitted a proposal to rust’s document. An important part of my whole proposal is a brief and brief introduction to those who may have heard of rust so that they can determine whether rust is suitable for them. A few days ago, I saw a wonderful speech and thought it could be a […]

  • Rust programming video tutorial (Advanced) – 017_ 2 messaging 2

    Time:2021-9-12

    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. Channel and ownership transfer(1) Example: use std::thread; use std::sync::mpsc; fn main() { let (tx, rx) = mpsc::channel(); thread::spawn(move || { let val = String::from(“hi”); tx.send(val).unwrap(); println! (“val is {}”, val);// Error, Val cannot be used here because the ownership of Val has […]

  • Rust ownership

    Time:2021-8-31

    As a java developer, everything I know about memory allocation is handled by some processes called garbage collection. This is the problem of the JVM, not mine.So when I openRust BookI became a little worried when I saw that rust had no garbage collection mechanism. Should the responsibility for dealing with memory management rest on […]