Meaning of the ampersand '&' and star '*' symbols in Rust

前端 未结 3 2021
既然无缘
既然无缘 2020-12-05 13:16

Despite thoroughly reading the documentation, I\'m rather confused about the meaning of the & and * symbol in Rust, and more generally about wh

3条回答
  •  春和景丽
    2020-12-05 13:47

    From the docs for std::ops::Add:

    impl<'a, 'b> Add<&'a i32> for &'b i32
    impl<'a> Add<&'a i32> for i32
    impl<'a> Add for &'a i32
    impl Add for i32
    

    It seems the binary + operator for numbers is implemented for combinations of shared (but not mutable) references of the operands and owned versions of the operands. It has nothing to do with automatic dereferencing.

提交回复
热议问题