SShortSingh.
Back to feed

How Rust Handles Inheritance: Composition and Traits Replace Class Hierarchies

0
·1 views

Rust does not support classical inheritance as seen in C++ or Java, instead relying on structs, traits, and composition to achieve code reuse. A developer maintaining epdsi, a no_std e-paper display driver crate, encountered this distinction while modeling two chip families where sibling controllers share most logic. In Rust, shared behavior is wrapped as an inner struct field, and each method must be manually forwarded, unlike Java where subclasses inherit everything automatically via extends. Traits with default methods offer partial relief but cannot share fields across types, leaving delegation boilerplate to be written by hand. The article illustrates how Rust's design philosophy favors explicit composition over implicit inheritance, trading conciseness for clarity and control.

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 ·

Technical English for Security Engineers: A Practical Guide to Workplace Communication

A Russian-language guide published on DEV Community addresses the challenge many Russian-speaking IT and security professionals face when using English in international work environments. The article argues that the goal is not to master the entire language but to build a focused toolkit of phrases and patterns for specific workplace scenarios. Key use cases covered include writing status updates, explaining security findings, describing risk and impact, and communicating professionally in tools like Slack. The guide emphasizes that effective technical English prioritizes clarity and actionability over linguistic complexity, stressing that messages should answer what is happening, who owns the next step, and what action follows. The author draws on personal experience working with international engineering teams and American recruiters to illustrate how practical communication skills matter more than formal language proficiency.

0
ProgrammingDEV Community ·

Travel Site Uses LLM for Moderation but Lets Humans Have the Final Say on Negative Reviews

A developer building 'Back From My Trip', a travel review site, has designed an AI moderation pipeline that explicitly protects negative reviews from being automatically rejected. The system assigns every piece of content a moderation status — approved, needs_review, or rejected — with row-level database security ensuring only approved content is publicly visible. While the AI can approve content autonomously, it cannot issue a final rejection for text-based opinions; any AI-flagged rejection is routed to a human admin queue for confirmation or override. When the moderation system fails or exceeds its budget, content defaults to needs_review rather than auto-approval, ensuring failures never allow spam through or silence a legitimate opinion. The developer also patched an early security flaw where client-side text could be swapped before moderation, replacing it with a server-side trigger system that processes only stored row IDs.

0
ProgrammingDEV Community ·

Ephemora Cell WASM sandbox blocks all 8 attack vectors that Docker missed for AI code

Ephemora Cell is an open-source, capability-based WebAssembly sandbox designed to safely execute untrusted code written by AI agents and tools. Unlike traditional container approaches, it operates beneath existing agent frameworks, granting guest code only explicitly permitted capabilities while blocking everything else by default. In testing against eight documented attack primitives, a standard Docker container blocked none, while Ephemora Cell blocked all eight, covering vectors such as shell access, forking, sockets, and filesystem escapes. The project, released under the Apache-2.0 license, supports any language that compiles to WASI/WASM and includes a GitHub Action for sandboxed CI runs. Developers building AI agents or MCP tools can install it via pip and run the included attack scripts to independently verify its security boundaries.

0
ProgrammingDEV Community ·

GPT-6 Astra Independently Builds a Puzzle, Supply-Chain Model, and Booklet Tool

OpenAI's GPT-6 Astra ran three independent AI-agent experiments, published on 4 September, in which separate agents built a string-based puzzle game called Loose End, a supply-chain simulation called The Order Echo, and a single-sheet booklet layout tool called Pocket Press. Each project went through a structured prototype review process before refinement, with a coordinating agent identifying and flagging issues for builders to correct. In Loose End, a logic puzzle involving a finite string, pegs, and bells, an early input bug ignoring brief keypresses was caught and fixed before the game was finalised. The Order Echo models how different ordering policies affect a four-tier supply chain, with its interface allowing users to inspect weekly demand and order arithmetic on a shared scale. Pocket Press arranges an eight-page booklet onto a single A4 or US Letter sheet and, following reviewer feedback, gained discoverable save options, folding instructions, and the ability to reload editable source files.

How Rust Handles Inheritance: Composition and Traits Replace Class Hierarchies · ShortSingh