Rust is getting a new `only` bounds syntax to replace the limited `?Sized` opt-out mechanism. The current `Sized`/`?Sized` binary doesn't scale to a richer hierarchy of sizedness traits (`Sized`, `MetadataSized`, `MaybeSized`), which is needed for ARM Scalable Vector Extensions and extern types. `only` bounds let you specify exactly which level of a trait hierarchy you require (e.g., `T: only MetadataSized`) while disabling higher default bounds, and they compose cleanly with other bounds. The post also explores a speculative second family of default traits around value access/movement/destruction (`Move`, `Destruct`, `Forget`, `Leak`, `Access`), showing how `only` bounds would work across multiple families. Examples include how `Option::map` would use `only Move`, `Option::or` would need `only Move + Destruct`, and `Rc` would use `only MaybeSized + only Leak`. The feature is being driven by the ARM team as part of the Sized Hierarchy and Scalable Vector Extensions project goal.

19m read timeFrom smallcultfollowing.com
Post cover image
Table of contents
Rust generics have a Sized bound by default todayYou opt out with ?SizedBut Sized vs ?Sized isn’t enough for everything we needA richer Sized hierarchyProblem: ?Sized notation doesn’t scale to this hierarchySolution: only boundsonly bounds work like normal bounds: ask for what you needonly bounds allow for new levels to be added lateronly bounds compose normallyScaling only to other “default bound families” (speculative)How only bounds could work in the presence of multiple familiesExamplesFrequently asked questionsConclusion
1.2K Impressions