Skip to main content
Filter by
Sorted by
Tagged with
3 votes
1 answer
83 views

I run into this same problem with a different flavor over and over and I'm not sure entirely how to describe it, so I'll simply give an example and explain how I'm stuck. I'm working on an ECS system ...
gjh33's user avatar
  • 121
3 votes
2 answers
116 views

I am writing a Rust crate where I have a struct whose field implements a trait, and I'd like to provide a feature where: #[cfg(not(feature = "dyn"))]: struct field is T, statically ...
Kyle Carow's user avatar
1 vote
0 answers
163 views

I define an attribute of type MyAbstractClass (abstract class), which takes a value of a concrete subclass MyConcreteClass. When I hit "Go to Definition" in VSCode at poke in self.item.poke()...
paperskilltrees's user avatar
3 votes
2 answers
219 views

I have this code open class Shape { open fun number(m: Shape) = "1" open fun number(m: Rectangle) = "2" } class Rectangle : Shape() { override fun number(m: Shape) = &...
Andrea's user avatar
  • 566
0 votes
1 answer
57 views

I have a vector of dynamic dispatch references that implement an extended trait. I would also like to be able to pass them in to a function that accepts the base trait: use std::borrow::BorrowMut; ...
Mad Physicist's user avatar
0 votes
1 answer
599 views

I want a dyn reference to a trait object, on which I have a method, taking a closure as argument: trait DynTrait { fn dyn_method(&mut self, closure: impl FnMut(&str) + 'static); } // ... ...
puaaaal's user avatar
  • 340
4 votes
2 answers
376 views

Problem Statement I have a set of structs, A, B, C, and D, which all implement a trait Runnable. trait Runnable { fn run(&mut self); } impl Runnable for A {...} impl Runnable for B {...} impl ...
RBF06's user avatar
  • 2,491
1 vote
1 answer
100 views

The goal is to get a functor to the Base::Print. #include <functional> #include <iostream> using namespace std; class Base { public: virtual void Print() { cout << "...
Samarth S's user avatar
  • 335
3 votes
1 answer
3k views

I'm on the nightly version #![feature(async_fn_in_trait)] use std::sync::Arc; trait IUserRepository { async fn find_by_email(&self, email: &str) -> bool; } struct Container { ...
hexal's user avatar
  • 325
4 votes
1 answer
455 views

While the C++ standard leaves the implementation of virtual dispatch up to the compiler, there are only 3 major compilers (gcc, clang and msvc) at this point. How do they implement virtual dispatch, ...
Yakk - Adam Nevraumont's user avatar
0 votes
2 answers
181 views

I wrote two structs that implement a common trait Solve. Solve has an associated type Answer with trait bound Display. I want the function create_solver to return a trait object of Solve. I need help ...
stackcycle's user avatar
1 vote
1 answer
111 views

I know that generally you can't have something like Vec<dyn Iterator>> because of course you need to specify the associated type. Now, I can have Vec<Box<dyn Iterator<Item=i32>>...
cadolphs's user avatar
  • 9,723
1 vote
1 answer
150 views

Rust beginner here. I have a number of algorithms that are almost identical but, at the final step, they all aggregate the results in slightly differently ways. Let's say the Algorithm does the ...
Big AL's user avatar
  • 553
3 votes
4 answers
1k views

Lets say I'm trying to write multiple handlers for multiple message types. enum MESSAGE_TYPE { TYPE_ZERO, TYPE_ONE, TYPE_TWO, TYPE_THREE, TYPE_FOUR }; One solution might be void handler_for_type_one(....
jedwards's user avatar
  • 30.3k
0 votes
0 answers
43 views

If run without changes, test_method() is called correctly for both variants in the function get_test_vector(): //! handler.rs use enum_dispatch::enum_dispatch; #[enum_dispatch] trait CommonTrait { ...
DWin's user avatar
  • 31
1 vote
1 answer
154 views

late-binding or runtime-polymorphism needs 2 things: a base pointer and a virtual method. class FrameWorkClassBase { public: virtual void method() = 0; }; class FrameWorkClassDerived: public ...
Self's user avatar
  • 194
0 votes
1 answer
85 views

I am reading the Wikipedia article about CLOS. It says that: This dispatch mechanism works at runtime. Adding or removing methods thus may lead to changed effective methods (even when the generic ...
Pedro Delfino's user avatar
2 votes
0 answers
191 views

Does anyone know if there's any way to reduce the amount of gc and/or dynamic dispatch for a gradient call in flux? I've tried using FastClosures.jl, as well as wrapping loss into a callable struct to ...
WhiffleFish's user avatar
1 vote
1 answer
224 views

Apologies for the convoluted title! I'm new to rust, and I'm trying to solve a very specific problem. None of the solutions I've tried so far seem to work nicely within the language bounds. I have a ...
jasbury's user avatar
  • 35
2 votes
1 answer
2k views

use once_cell::sync::OnceCell; pub trait SomeTrait {} pub struct Impl1 {} impl SomeTrait for Impl1 {} pub static GLOBAL_THING: OnceCell<Box<dyn SomeTrait>> = OnceCell::new(); pub fn ...
Clayton Rabenda's user avatar
4 votes
1 answer
2k views

Recently I've been working on learning advanced Rust. As part of that, I'm learning to use dynamic dispatch. In my tinkering I've run across a bit of an issue. For some reason, I can't seem to access ...
In Hoc Signo's user avatar
3 votes
1 answer
136 views

I encountered the use of predefined class wide access types as the main parameter to a subprogram many times in our code base and would like to know whether it's a flaw in the design or if it has some ...
Erik Stens's user avatar
  • 1,807
0 votes
0 answers
21 views

Following code results in compilation error. error: no matching function for call to ‘D::print(int)’ Error is at following line d_ptr->print(5); #include<iostream> using std::cout; ...
Pandav Patel's user avatar
0 votes
1 answer
550 views

I am trying to make a toy compiler for an object oriented language which supports dynamic dispatch and simple inheritance. Meaning any class Child that extends a parent can be used whenever a Parent ...
Desperados's user avatar
4 votes
1 answer
459 views

Please consider the following Swift 5 code: protocol P: class { func call_foo() func foo() func call_bar() func bar() } extension P { func call_foo() { foo() } func foo() { ...
imre's user avatar
  • 1,747