本文介绍了Rust 中 &4 等字面引用的所有者是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,特定值只有一个所有者(Rc 之类的内容除外).那么下面的值 4 的所有者是什么,因为变量 myVar 从某物借用了它?我想知道那是什么东西.

Normally, there is only one owner for a specific value (except for things like Rc<T>). Then what is the owner of the value 4 below since the variable myVar borrows it from something? I want to know what is that something.

let myVar = &4;

推荐答案

Literals, be they:

Literals, be they:

  • 数字文字,如 4
  • 字符串文字,例如 "Hello, World"

具有 'static 生命周期,因为它们的值被硬编码到库或可执行文件本身中.例如,在 Linux 上,它们可以在 ELF 二进制文件的 .text 段或 .rodata 段中找到.

Have a 'static lifetime as their value is hard-coded into the library or executable itself. For example, on Linux, they would be found either in the .text segment or the .rodata segment of the ELF binary.

从这个意义上说,您可以认为它们归程序本身所有.

In that sense, you can think of them as being owned by the program itself.

这篇关于Rust 中 &amp;4 等字面引用的所有者是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 08:18