trait-objects Questions
1
I have a trait MyTrait, and I want all trait objects &dyn MyTrait to be comparable to each other and to nothing else. I have that now based on How to test for equality between trait objects?.
T...
Lumpfish asked 24/3, 2018 at 15:2
1
Solved
trait FooTrait {}
struct FooStruct;
impl FooTrait for FooStruct {}
fn main() {
let maybe_struct: Option<dyn FooStruct> = None;
// Does not compile
let maybe_trait: Option<Box<dyn...
Karlenekarlens asked 19/2, 2018 at 10:25
1
Solved
First of all, I'm not asking what's the difference between &mut and ref mut per se.
I'm asking because I thought:
let ref mut a = MyStruct
is the same as
let a = &mut MyStruct
Consid...
Darling asked 6/12, 2017 at 17:45
2
Solved
When writing code with traits you can put the trait in a trait bound:
use std::fmt::Debug;
fn myfunction1<T: Debug>(v: Box<T>) {
println!("{:?}", v);
}
fn myfunction2<T: Debug>...
Saltigrade asked 17/7, 2017 at 19:2
2
Solved
I have the following code:
extern crate futures; // 0.1.24
use futures::Future;
use std::io;
struct Context;
pub trait MyTrait {
fn receive(context: Context) -> Future<Item = (), Error =...
Pansie asked 15/7, 2017 at 10:9
2
Solved
I am struggling with the basics of object safety. If I have this code
struct S {
x: i32,
}
trait Trait: Sized {
fn f(&self) -> i32
where
Self: Sized;
}
fn object_safety_dynamic(x: Trai...
Ry asked 21/5, 2017 at 11:18
1
Solved
I cannot get this to compile without using a closure. I'm trying to get the function apply to return the correct kind of closure in the first place.
#![feature(conservative_impl_trait)]
#![allow(d...
Ladawnladd asked 16/9, 2016 at 23:19
3
Solved
Can anyone tell what the problem is with the following code? The compiler is complaining about lifetimes, but the error message makes absolutely no sense. I've tried everything I could think of, bu...
Jobless asked 6/9, 2016 at 1:28
3
Solved
I have the following code
extern crate rand;
use rand::Rng;
pub struct Randomizer {
rand: Box<Rng>,
}
impl Randomizer {
fn new() -> Self {
let mut r = Box::new(rand::thread_rng()); /...
Sonnnie asked 29/8, 2016 at 23:52
1
I have originally asked this question here, but it was marked as duplicate, although it duplicates only a part of it in my opinion, so I have created a more specific one:
Consider the following co...
Acceleration asked 16/6, 2015 at 7:26
1
Solved
I'd like to send a trait object between threads, but can't figure out if it's possible. It seems like it might not be, as they apparently do not fulfill the Send trait.
The following code demonstr...
Lonlona asked 3/9, 2014 at 16:32
© 2022 - 2024 — McMap. All rights reserved.