Rust programming video tutorial (Advanced) – 011_ 3 dereference polymorphism


Video address

Headline address:…
Station B address:

Source address

GitHub address:…

Explanation content

1. Dereference forced polymorphism
Example: follow the example above

fn hello(name: &str) { 
    println!("Hello, {}!", name); 

fn main() { 
    let m = MyBox::new(String::from("Rust")); 
    hello(&m); // When dereferencing here, force polymorphism and change & string to & str. otherwise, you need: Hello (& (* m) [..]; 

2. Dereference polymorphism and variability interaction
There are three cases of dereference polymorphism:

  • When   T: Deref   Shi Cong  & T   reach  & U。
  • When   T: DerefMut   Shi Cong  & mut T   reach  & mut U。
  • When   T: Deref   Shi Cong  & mut T   reach  & U。 (Note: the opposite is impossible here)

This work adoptsCC agreement, reprint must indicate the author and the link to this article

Linghu rushed

Recommended Today

VBS tutorial: objects – regular expression (regexp) objects

Regular expression (regexp) objectProvides simple regular expression support. explainThe following code illustrates the usage of regexp object: Function RegExpTest(patrn, strng) Dim regex, match, matches’ create variables. Set regex = new regexp ‘establish a regular expression. Regex. Pattern = pattern ‘sets the pattern. Regex.ignorecase = true ‘sets whether characters are case sensitive. Regex. Global = true […]