01 Paths in Rust ` :: `

In the Rust language, path:: has three ways to use, namely:

1. For type imports

Path:: The most common way to use it is to introduce various types from the outside (such as Trait, structure, enumeration, etc.)

In addition, we can also define types and functions in multi-layer modules, and then access them through paths, such as:

2. For method calls

When a type implements the same method in two traits, you need to use :: to explicitly specify which method in the trait to call, such as:

3. For type specification

Sometimes, we want to be more specific about the type of data to be parsed or created, so we need the turbofish syntax::<> to specify the specific type of the generic, such as:

The above is the common usage of :: in the Rust language. Sample code Github address:

https://github.com/shiyivei/from-principle-to-practice/blob/main/src/principle-and-practice/src/lexical_structure/path.rs

More content welcome to pay attention

Guess you like

Origin blog.csdn.net/weixin_51487151/article/details/129338224