Rust 2024 edition

러스트 2024 에디션

An edition opts code into new syntax and interpretation rules without forcing all crates to change together.

···
html
<div class="visual edition" data-step="0"><div class="visual-head"><strong>RUST EDITION</strong><i></i></div><div class="visual-scene"><div class="edition-source mono">same source</div><div class="edition-toggle"><span>2021</span><i></i><span>2024</span></div><div class="edition-rule">rules applied at crate boundary</div></div><div class="visual-caption"></div><div class="visual-dots"><b></b><b></b><b></b></div></div>
css
.visual{width:min(95vw,760px);height:min(91vh,330px);padding:clamp(9px,2.5vmin,18px);display:flex;flex-direction:column;gap:clamp(6px,1.7vmin,11px);border:1px solid var(--line);border-radius:13px;background:var(--surface);font:500 clamp(12px,3.4vmin,16px)/1.25 var(--font-sans,-apple-system),sans-serif}
.visual-head{display:flex;align-items:center;justify-content:space-between;gap:8px;min-height:19px;color:var(--accent)}.visual-head strong{font-size:1em}.visual-head i{display:block;width:8px;height:8px;flex:none;border-radius:50%;background:var(--accent);animation:visual-pulse 1.3s infinite}@keyframes visual-pulse{50%{opacity:.25}}
.visual-scene{position:relative;flex:1;min-height:0;overflow:hidden}.visual-caption{min-height:2.4em;display:grid;place-items:center;text-align:center}.visual-dots{display:flex;justify-content:center;gap:4px}.visual-dots b{display:block;width:15px;height:3px;border-radius:3px;background:var(--line)}.visual-dots b.on{background:var(--accent)}
.visual-scene *{box-sizing:border-box}.visual-scene .mono{font-family:ui-monospace,monospace}.visual-scene .muted{color:var(--muted)}.visual-scene .lit{border-color:var(--accent)!important;background:color-mix(in srgb,var(--accent) 14%,var(--surface))!important;color:var(--fg)!important}
.edition .visual-scene{display:flex;flex-direction:column;justify-content:center;align-items:center;gap:9px}.edition-source{border:1px solid var(--line);border-radius:6px;padding:6px 16px;background:var(--bg)}.edition-toggle{display:flex;align-items:center;gap:8px}.edition-toggle span{font:600 12px ui-monospace,monospace}.edition-toggle i{display:block;width:60px;height:24px;border-radius:20px;background:var(--line);position:relative}.edition-toggle i:before{content:'';display:block;position:absolute;top:3px;left:3px;width:18px;height:18px;border-radius:50%;background:var(--accent);transition:left .4s}.edition[data-step="1"] .edition-toggle i:before,.edition[data-step="2"] .edition-toggle i:before{left:39px}.edition-rule{font-size:12px;color:var(--muted);text-align:center}.edition[data-step="2"] .edition-rule{color:var(--accent)}
js
const root=document.querySelector('.visual'),cap=root.querySelector('.visual-caption'),dots=[...root.querySelectorAll('.visual-dots b')],captions=["Crate selects 2021 rules","Switch to 2024 rules","Other crates keep their edition"];let step=0;function advance(){root.dataset.step=String(step);cap.textContent=captions[step];dots.forEach((d,i)=>d.classList.toggle('on',i===step));if(root.classList.contains('generic')){root.querySelector('.generic-input').textContent=step===3?'"hi"':'7';root.querySelector('.generic-output').textContent=step===3?'"hi" : string':'7 : number'}if(root.classList.contains('union'))root.querySelector('.set-value').textContent=step%2?'value: "seven"':'value: 7';step=(step+1)%captions.length}advance();let timer=setInterval(advance,1100);root.addEventListener('pointerdown',()=>{clearInterval(timer);advance()})

Rust 2024 is a bundle of language rules selected through a Cargo package edition. Editions work per crate, so crates using different editions can coexist in one program.

The demo switches the rule set applied to a source file. Migration tooling helps, but code affected by new keywords or scope rules still needs review.

When to use

Use it when migrating a crate or building dependencies that use different Rust editions.

Open as page ↗