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

推荐订阅源

Last Week in AI
Last Week in AI
有赞技术团队
有赞技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
人人都是产品经理
人人都是产品经理
博客园 - 司徒正美
博客园 - 聂微东
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 叶小钗
罗磊的独立博客
IT之家
IT之家
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
Hugging Face - Blog
Hugging Face - Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
Netflix TechBlog - Medium
MyScale Blog
MyScale Blog
J
Java Code Geeks
L
LangChain Blog
S
SegmentFault 最新的问题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
G
Google Developers Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How Rust Decides Whether an Array Is Copy
Jazz Thumyat 🦀 · 2026-06-27 · via DEV Community

Jazz Thumyat 🦀

In Rust, we all know that Vec is not Copy, which means it does not implement the Copy trait. As a result, after iterating over a Vec like this:

let num = vec![1, 2, 3];

for i in num {
    println!("{}", i);
}

println!("{:?}", num); // compiler error: value borrowed here after move

the compiler reports an error because num has been moved. When we write for i in num, Rust desugars it into something like for i in num.into_iter(). The into_iter method takes self by value:

#[inline]
fn into_iter(self) -> Self::IntoIter {
    // ...
}

Because Vec<T> is not Copy, passing it by value moves it into the iterator. Ownership is transferred to the iterator, so num can no longer be used after the loop.

Now let’s try the same thing with an array:

let num = [1, 2, 3];

for i in num {
    println!("{}", i);
}

println!("{:?}", num); // works

There is no compiler error this time. Why?

The type of num is [i32; 3]. Since i32 implements Copy, the array also implements Copy. That means num is copied into the loop instead of being moved, and the original array remains available after the loop.

Now consider an array of Strings:

let strs = ["one".to_string(), "two".to_string()];

for s in strs {
    println!("{}", s);
}

println!("{:?}", strs); // compiler error: value borrowed here after move

This produces the same compiler error as the Vec example.

The reason is that String does not implement Copy. As a result[String; 2] is also not Copy. When the array is passed to into_iter, it is moved into the iterator, making strs unavailable afterward.

So how does Rust know that some arrays are Copy while others are not?

This isn’t compiler magic. It’s implemented in the standard library with a blanket implementation:

impl<T: Copy, const N: usize> Copy for [T; N] {}

This implementation says:

For any type T that implements Copy, and for any array length N, the array [T; N] also implements Copy.

As a result:

  • [i32; 3] is Copy because i32 is Copy.
  • [bool; 10] is Copy because bool is Copy.
  • [String; 2] is not Copy because String is not Copy.

In other words, whether an array implements Copy depends entirely on whether its element type implements Copy.