expression
Adapt a legacy interface without owning the source
An adapter translates between interfaces while preserving the original implementation. A borrowed adapter can expose a domain-specific contract without cloning the underlying resource. Here an integer sensor reports tenths of a degree; the adapter exposes degrees as f64. The conversion and lifetime are explicit. Expected result (NOT RUN): 23.5 C Common mistake: Changing the original interface globally or hiding a unit conversion. Static Rust example; not a verified ByteMind executable assessment.
Formal Syntax & Structure
rust syntaxrust
struct Adapter<'a>(&'a Legacy); impl Sensor for Adapter<'_>Working Example
Example Snippetrust
struct Legacy { tenths: i16 }trait Sensor { fn degrees(&self) -> f64; }struct Adapter<'a>(&'a Legacy);impl Sensor for Adapter<'_> { fn degrees(&self) -> f64 { f64::from(self.0.tenths) / 10.0 }}fn main() { let source = Legacy { tenths: 235 }; let sensor = Adapter(&source); println!("{:.1} C", sensor.degrees());}