SShortSingh.
Back to feed

Rust Ownership Explained: Copy Trait, Value Drop, and Drop Order

0
·1 views

Rust's memory model enforces a single-owner rule for every value, managed by the borrow checker, which ensures each value is freed exactly once. When a value is assigned to a new location, ownership transfers via a move, unless the type implements the Copy trait, which allows a bitwise duplication instead. Types like Box cannot implement Copy because doing so would cause two variables to claim ownership of the same heap memory, leading to a double-free error. When a value goes out of scope, Rust automatically drops it along with any values it owns, recursively freeing nested data. Variables are dropped in reverse order of declaration, while nested values within a type are dropped in source order.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Speculative Decoding Speedups Depend More on Acceptance Rate Than Hardware

A developer investigating slower-than-expected speculative decoding performance in LLM inference found that Apple Silicon's MPS backend was initially blamed for the gap due to high fixed dispatch costs per model call. However, hardware-agnostic FLOPs-based theoretical calculations using Leviathan et al.'s formula revealed the algorithm itself could not surpass 1.0x speedup at the observed acceptance rates, even with zero hardware overhead. Switching from a 0.5B to a 1.5B draft model — expected to improve distribution matching with the 3B verifier — produced highly variable results, with acceptance rates swinging from 19% to 86% across runs on the same prompt type. The investigation concluded that acceptance rate, driven by prompt characteristics and draft-verifier distribution alignment, is the primary ceiling on speculative decoding gains. Hardware overhead compounds the problem but is not the root cause of underperformance.

0
ProgrammingDEV Community ·

Developer explores entropy as a metaphor for software aging and technical debt

A software developer spent a late-night session discussing the concept of entropy in software systems with an AI agent called Hermes Agent, built by Nous Research. Drawing on Lehman's Laws (1974–1996), the conversation framed technical debt not as a financial metaphor but as accumulated entropy that compounds over time without deliberate effort to reduce it. The AI agent described software coupling as analogous to gravity — invisible yet pervasive, making systems harder to change as they grow more interconnected. The developer highlighted that refactoring should be treated as essential thermodynamic work rather than optional cleanup. The post also referenced Hassan's 2009 research showing that applying Shannon's entropy formula to code change patterns can statistically predict software defects.

0
ProgrammingDEV Community ·

Developer Builds Cross-Platform Disk Usage Analyzer in C Using Only Standard Libraries

A developer created a terminal-based disk usage analyzer in C without any external libraries, relying solely on the C standard library and OS system calls. The tool recursively scans directories using nftw(), reports total, used, and available disk space, and displays files sorted by size with ASCII bar charts. Building the project involved fixing three notable bugs, including a faulty realloc call that omitted sizeof, unfiltered directory entries in the file list, and missing cross-platform disk stat support for Windows. Cross-platform compatibility was achieved by splitting disk space queries between statvfs on Linux and macOS and GetDiskFreeSpaceExA on Windows behind a unified function. The single-file project builds on both Linux and Windows via CMake, with the developer noting plans to add depth limits and directory exclusions as future improvements.

0
ProgrammingDEV Community ·

Developer Builds ClipMark Extension to Fix Notion Web Clipper's Long-Standing Flaws

A developer has launched ClipMark, a Manifest V3 Chrome extension designed to address persistent issues with Notion's official Web Clipper, which holds a 3.4-star rating on the Chrome Web Store. The extension offers three core actions: copying clean Markdown to clipboard, downloading a Markdown file with YAML frontmatter, and saving content directly to a Notion database via official OAuth. Unlike the official clipper, ClipMark saves every clip locally before attempting any network call and uses exponential backoff retries to ensure nothing is silently lost. An AI backend powered by GPT-4o-mini automatically generates tags and a one-line summary for each clip, both editable before saving. ClipMark's first two features require no account, while Notion integration and unlimited AI features are available for $4.99 per month or $39 per year, with 20 free AI clips offered monthly.