`alloc::rc::Rc` 和 `std::rc::Rc` 有什么区别? [英] What is the difference between `alloc::rc::Rc` and `std::rc::Rc`?

查看:44
本文介绍了`alloc::rc::Rc` 和 `std::rc::Rc` 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇这两个模块在实践中是否有区别?如果没有,那为什么会有这两个重复呢?

I'm curious is there a difference between these two modules in practice? And if not, why have these two duplicates then?

推荐答案

std::rc::Rc 只是 alloc::rc::Rc 的重新导出代码>.您可以在 src/std/lib.rs 中看到整个rc 模块重新导出:pub use alloc::rc;

std::rc::Rc is just a re-export of alloc::rc::Rc. You can see in src/std/lib.rs that the whole rc module is re-exported: pub use alloc::rc;

alloc crate 适用于任何类型的内存分配.引用计数、盒装、原始分配和对底层分配器的一般访问(在 Rust 中通常是 jemalloc).由于 Rc 类型是如此常见的类型,它应该存在于标准库中,但是 alloc crate 不应该是标准库的一部分,只是 alloc 的 >rc 模块重新导出到标准库.这使用户不必关心 alloc crate,而是提供一个干净的标准库,没有奇怪的东西,使用起来很不舒服.

The alloc crate is for any kind of memory allocations. Reference counted, Boxed, raw allocations and general access to the underlying allocator (often jemalloc in Rust). Since the Rc type is such a common type that it should exist in the standard library, but the alloc crate should not be a part of the standard library, just the rc module of alloc is re-exported to the standard library. This saves the user from having to care about the alloc crate, and instead offers a clean standard library without odd stuff that is prone to be uncomfortable to use.

这篇关于`alloc::rc::Rc` 和 `std::rc::Rc` 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆