Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

castaway

> DevOps
Open source

Safe, zero-cost downcasting for limited compile-time specialization.

185 stars0 likes1 views
WebsiteGitHub

About

Safe, zero-cost downcasting for limited compile-time specialization.

Castaway

Safe, zero-cost downcasting for limited compile-time specialization.

Documentation

Please check out the documentation for details how to use Castaway and its limitations. To get you started, here is a really simple, complete example of Castaway in action:

…

Minimum supported Rust version

The minimum supported Rust version (or MSRV) for Castaway is stable Rust 1.38 or greater, meaning we only guarantee that Castaway will compile if you use a rustc version of at least 1.38. Any changes to the supported minimum version will be called out in the release notes.

What is this?

This is an experimental library that implements zero-cost downcasting of types that works on stable Rust. It began as a thought experiment after I had read this pull request and wondered if it would be possible to alter the behavior of a generic function based on a concrete type without using trait objects. I stumbled on the "zero-cost"-ness of my findings by accident while playing around with different implementations and examining the generated assembly of example programs.

The API is somewhat similar to Any in the standard library, but Castaway is instead focused on ergonomic compile-time downcasting rather than runtime downcasting. Unlike Any, Castaway does support safely casting non-'static references in limited scenarios. If you need to store one or more Box objects implementing some trait with the option of downcasting, you are much better off using Any.

License

This project's source code and documentation is licensed under the MIT license. See the LICENSE file for details.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rustcastingrustspecialization

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
CategoryDevOps
PricingOpen source

> Related tools

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理