惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
The Register - Security
The Register - Security
S
Securelist
Simon Willison's Weblog
Simon Willison's Weblog
T
The Exploit Database - CXSecurity.com
V
Vulnerabilities – Threatpost
NISL@THU
NISL@THU
P
Privacy & Cybersecurity Law Blog
V2EX - 技术
V2EX - 技术
O
OpenAI News
N
News and Events Feed by Topic
AI
AI
P
Proofpoint News Feed
Schneier on Security
Schneier on Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Cloudbric
Cloudbric
Help Net Security
Help Net Security
C
Cyber Attacks, Cyber Crime and Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Security Latest
Security Latest
Application and Cybersecurity Blog
Application and Cybersecurity Blog
L
LINUX DO - 热门话题
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
The Hacker News
The Hacker News
Hacker News - Newest:
Hacker News - Newest: "LLM"
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Google DeepMind News
Google DeepMind News
H
Hacker News: Front Page
C
Cisco Blogs
Webroot Blog
Webroot Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hacker News: Ask HN
Hacker News: Ask HN
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The Last Watchdog
The Last Watchdog
PCI Perspectives
PCI Perspectives
AWS News Blog
AWS News Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Forbes - Security
Forbes - Security
I
Intezer
Project Zero
Project Zero
C
CERT Recently Published Vulnerability Notes
T
Tenable Blog
TaoSecurity Blog
TaoSecurity Blog
S
Security @ Cisco Blogs
N
News | PayPal Newsroom
H
Heimdal Security Blog
W
WeLiveSecurity

The Rust Programming Language Forum - Latest posts

What's everyone working on this week (21/2026)? Rust Function Call with one Param Iced + Canvas + Text: How do I create a style for canvas text "Value dropped while borrowed" as a lifetime mismatch Weird `use of moved value` behaviour Slightly surprising behavior of a while loop Clap: how to disable options after a certain positional argument How do i tell rust-analyzer what kind of bracket to use for a macro? Iterator + Borrow Checker: Work around borrowing already borrowed mutable variable Requesting data via mavlink SKILLS.md for Rust development 🧵 Stringlet UTF-8 Hack Option Niche? Iterator + Map - How do divide every element, including the last element, by the last element Why can't we store returned value of a function in a variable if one of the parameters goes out of scope My first crate :D, floop: A more convenient and less error prone replacement for loop `{ select! { .. }}` Sorting is slow because architectures are wrong — zan-sort redesigns the architecture, not the algorithm Iced Font - Create a custom monospace font to display dollar amounts Is the UnsafePinned RFC wrong about being able to return `&mut T` from `get_mut_unchecked`? Fixing Polars 0.37 compilation errors: Hashbrown 0.17 dependency conflict and decimal parsing Any plans for improving error diagnostic in Rust 2.0? How do I build completely offline? Is `&mut T -> &mut ManuallyDrop<T>` well-defined and sound? Would you use this? — fixtura, declarative fake data injection for tests Foreign trait restrictions on native types make generics hard to use Cargo Exclude Directive Compiler reasoning around a modulo counter Multiple mutable references to elements within one vector Handling non-`Send` data in a `Send` closure Review: Static Multi Pool Allocator Rmquickjs - High-level MicroQuickJS bindings for Rust Iced + Rusqlite + Chrono: Problem with custom error type Why can&#39;t the Rust compiler infer the T type parameter in this BTreeMap::range call? Beginner building a Rust backend framework (AI-assisted) — feedback appreciated C++ to Rust -- Exceptions Re-exporting a trait with a custom derive_macro Gold linker is deprecated Why is using PhantomData valid in this case? Code review for Static Pool Allocator Discussion on Synchronous Crate Concurrency Refactor using Stackful Coroutines Model in Rust Can a future used only by `async fn` assume it won&#39;t be polled again after becoming ready? High-performance `fast-powi` crate Looking for a pool based allocator Why is this legal? What does it mean for Rustc to run "out of TLS keys"? Using async/await internally with no internal runtime, but exposing a nonblocking poll API — is this a reasonable design? Testing functions that use randomness `cargo-path`: improve coding agents&#39; ability to find Rust documentation Rust task runners Lifetime weird case Windows - USB device not detected A random rustc-ice-[...].txt file appeared Develop rust where the environment is setup in a docker Undefined Behavior: in-bounds pointer arithmetic failed: attempting to offset pointer by 20 bytes, but got alloc238 which is only 1 byte from the end of the allocation Unbug 0.5 - Runtime debug assertions Is there a tiny error in section 6.2 Reference types? Vasya go to (his) Home 🏡 Lifetime woes implementing ratatui::Widget for a reference Rusqlite + Chrono: How do I simplify code to obtain chrono datetime value From OOP to Rust – struggling with code organization and data structure design Way to avoid a self-referential struct Rust RF and audio resources/communities Whyhttp - HTTP mocks that fail where the bug actually is Using tokio channel permits in a tower service Arc::increment_strong_count design question (cross-post) Ratatui detect arrow key press and release Feedback about post in medium Debugger not showing/offering variables? nestrs: a NestJS-style framework for Rust built on Axum and Tower Confusion about struct variance with &mut dyn How do I do hmr in rust How to call struct method as function pointer in loop Loops inside loops and mutable reference on Iterator VSCode - rust-analyzer - annoying re-builds due to RUSTC_BOOTSTRAP changed Borsh v1.6.1 example What's everyone working on this week (14/2026)? What's everyone working on this week (17/2026)? RawWakerVTable functions, did I write them correctly? Cargo test's verbose output - can I quiet it? Sem: semantic entity level version control CLI built with tree-sitter How do i get all the words in a string and convert it into a vector? Looking for feedback on my first tokenizer in Rust Frostmirror - (lightweight airgap alternative inspired from panamax and romt) - an offline cargo repository for airgap system that can be deployed through a docker image Does "ill-formed, no diagnostic required" exist in Rust? If a program is built with software floating-point emulation, is it affected by hardware floating-point environment? Rustc-link-lib static library How does crates.io and docs.rs store crates? Basic Object Oriented Programming in Rust Various input in one line error[E0080]: index out of bounds error when trying to install LuaCAD CSV to SQLite - Is it better to write records as they are being read Looking for feedback for a graph-based task scheduler This is my first project. I invented a new algorithm that even AI don't know. It's about bigint. And I'm 15. Thanks for watching. By the way, my crate named `nna` Why Windows rustc uses a different color scheme? Clap completion question Is RMW operation less prone to reading stale values than a pure load? Why are builds of my crate's test not consistent (cargo build vs cargo test vs VSCode-Test-Explorer) Type inference of generic parameters Cyw43 on STM32H723 Reducing code repetition with Vecs and fields Are there any object detection libraries out there for the Arduino?
`&T`, `&mut T`, `Pin<&mut T>` and `&Cell<T>`: Ways of Borrowing a `T`
@ArsenalAlex · 2026-04-22 · via The Rust Programming Language Forum - Latest posts

Disclaimer: This post is crossposted from a post of the same name in the unofficial Rust subreddit made by me, because I was baselessly accused of making an AI-generated post, so I apologize for the redundancy. I advise readers not to brigade other community and focus and ideas I propose, and politely point out if there is something wrong with my post - I kept the contents of the post the same for this purpose. I know that the last sentence of the post sounds AI-Generated, but I was just aggressively using passive language, and do not know how to word it better. Thank you for your attention.

Interior Mutability is usually considered to be an inherent property to a type - a type with interior mutability has very different invariants from a type that does not, and there are varying degrees of interior mutability too. And so it's not often thought that a type can be arbitrary borrowed as interior mutable; for example a T can't be borrowed as RefCell<T> because they do not have the same size - but Cell<T> (and UnsafeCell<T>) is special in this regard.

The key sparking this discussion is that a &Cell<T> can be obtained from a &mut T using Cell::from_mut - which can easily be proven to be safe.

This also works for slices (and arrays): a &[Cell<T>] can be obtained from a &mut [T] using Cell::from_mut and Cell::as_slice_of_cells. You may be surprised that Cell also accepts unsized types - these can be obtaining using an unsizing coercion on a reference - though they are not useful by themselves so they may as well not exist.

So any sliceable type like Vec<T> can be borrowed as copyable references to a slice that can be edited by multiple consumers - though not by multiple threads. As a consequence, unlike &mut [T], it is possible for &[Cell<T>]s to point to overlapping memory, like how two &Cell<T>s can point to the same object.

So why is Cell rarely brought up at all? Because there are two - and only two - things you can do with a &Cell<T>:

  • Swap values between two &Cell<T> using Cell::swap.
  • Copy the value behind &Cell<T> using Cell::get, but only if T: Copy.

...

That's it.

In fact, not only is &Cell<T> limited in behavior, it also lacks many capabilities of &T and &mut T, and is not treated specially by the compiler either:

  • They can not be projected to an inner field because there is no first-class language support.
    • Projection is a casting a &Cell<Struct> given struct Struct(A, B) into a &Cell<InnerField> like &Cell<A> or &Cell<B>.
    • Do you know if it is safe to project &Cell<Struct>?
    • Because it is safe to cast a &Cell<[T; N]> into &[Cell<T>; N] using Cell::as_array_of_cells, so I'm not sure if it is safe to do so for structs and write a safe Cell projection macro.
  • Cell is not a fundamental type like &T, &mut T, Box<T>, Pin<Ptr> (issue for fundamental attribute).
  • Cell cannot be used as self receivers like fundamental types, Rc<T> and Arc<T> (issue for arbitrary self types).
  • &mut T implicitly casts to &T, but not to &Cell<T>.

But unlike Box<T>, Rc<T> and Arc<T>, &Cell<T> can be obtained from &mut T, and so is independent of how T is stored.

Since Cell does not implement synchronization, it never implements Sync. Adding a lock to the type increases its size and it will cease to be a Cell.

A hypothetical SyncCell<T> would provide the same APIs as Cell<T> - including projection, if it is truly safe, but all accesses will be synchronized using an array of global locks to minimize contention. I do not know if there is a crate for this type yet.

The AtomicCell<T> in crate crossbeam also synchronizes using an array of global locks, but will transmute to their bespoke atomic implementation that supports uninitialized memory if the size and alignment of T match one of them (atomics in core also have nightly from_mut method). But unlike SyncCell<T>, projection is not safe because atomic access of different sizes are probably incompatible. While the API for from_mut has been removed, the author confirmed that re-adding the API is safe.

In conclusion, theoretically there are six mutually exclusive way of borrowing a T: &T, &mut T, Pin<&mut T>, &Cell<T>, &SyncCell<T> and &AtomicCell<T>, and projection support could theoretically be added for pins and cells (Pin<Ptr> has the pin-project crate, which is also maintained by the same author). This post invites readers to consider if the concept of Interior Mutability is not only a property of a type that must be decided beforehand, but also makes up separate counterparts of primitive references.