-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Labels
use caseA Rust/C++ interop usage exampleA Rust/C++ interop usage example
Description
Currently, it is very difficult to call most overloaded C++ functions from Rust, because Rust doesn't have first-class overload resolution.
This use case is supported by another project goal:
That project goal contains a FAQ including prior art and current workarounds.
Example Code
What's currently possible:
- using exact types and requiring non-overlapping impls
- using existing unstable features
- using provider traits to allow incoherence
Depends On
- Tracking issue for Fn traits (
unboxed_closures&fn_traitsfeature) rust-lang/rust#29625 - RFC: inherent trait implementation rust-lang/rfcs#2375
- Lossless Integer Round-Trips between Rust and C++ #6 (for integer overloads)
- Add missing
impl Fn for &mut F where F: Fnrust-lang/rust#148271 (maybe?)
Related Work
- Tracking issue: Allow autoderef and autoref in operators (experiment) rust-lang/rust#44762
- Allow using Fn(A, B, C) -> _ for unconstrained FnOnce::Output. rust-lang/rust#47815
- Cannot call implementations of the
Fn*traits on references rust-lang/rust#42736 (comment) - Tracking issue for experiments around coercions, generics, and Copy type ergonomics rust-lang/rust#44619
Previous Work
- https://internals.rust-lang.org/t/pre-pre-rfc-splatting-for-named-arguments-and-function-overloading/24012
- https://docs.rs/overload/latest/overload/ (only for operators)
- https://docs.rs/overloadf/latest/overloadf/ (for functions)
- cxx and Zngur rename overloads with numeric suffixes, but this can cause function name conflicts
User Questions
- https://users.rust-lang.org/t/is-there-a-simple-way-to-overload-functions/30937
- https://internals.rust-lang.org/t/discussion-about-overloading-forked-from-pre-rfc-named-arguments/16990
- https://users.rust-lang.org/t/why-rust-doesnt-have-function-overloading/80416
- https://internals.rust-lang.org/t/justification-for-rust-not-supporting-function-overloading-directly/7012
- https://stackoverflow.com/questions/24594374/how-can-an-operator-be-overloaded-for-different-rhs-types-and-return-values (outdated?)
Sources
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
use caseA Rust/C++ interop usage exampleA Rust/C++ interop usage example