I\'d like to have a LinkedList of trait object wrapper structs. The inner would be a stream type for either an Ssl or Non-Ssl stream. My hope was to pass the st
Ok, there are a few problems here. Working down the list of compiler errors:
:15:53: 15:68 error: the trait `core::marker::Sized` is not implemented for the type `HStream` [E0277]
:15 let mut list = Arc::new(Mutex::new(LinkedList::>::new()));
^~~~~~~~~~~~~~~
:15:53: 15:68 help: see the detailed explanation for E0277
:15:53: 15:68 note: `HStream` does not have a constant size known at compile-time
:15:53: 15:68 note: required by `Stream`
Because HStream does not have a compile-time computable size, it cannot be substituted for the type parameter T. All type parameters implicitly require the substituted type to be compile-time sized. If you want to allow dynamically sized types, you need to explicitly opt-out of this implicit bound by saying something like:
:15:53: 15:68 error: the trait `HStream` is not implemented for the type `HStream` [E0277]
:15 let mut list = Arc::new(Mutex::new(LinkedList::>::new()));
^~~~~~~~~~~~~~~
:15:53: 15:68 help: see the detailed explanation for E0277
:15:53: 15:68 note: required by `Stream`
A trait doesn't implement itself. You're asking for a type which implements HStream, but HStream doesn't implement itself (how would it?)
You have to provide a type which does.
:15:53: 15:68 error: the trait `HStream` cannot be made into an object [E0038]
:15 let mut list = Arc::new(Mutex::new(LinkedList::>::new()));
^~~~~~~~~~~~~~~
:15:53: 15:68 help: see the detailed explanation for E0038
:15:53: 15:68 note: the trait cannot require that `Self : Sized`
And here's the K-O problem: HStream cannot be used with dynamic dispatch, period. It's not object safe. This is most likely because of the Clone requirement.
The "fix" to all of the above is to redesign your types so that the problem doesn't exist. What that entails is impossible to know because there isn't enough context here to tell what you're trying to do.
At a blind stab, though, here's what it might look like without generics (which you don't appear to be using, anyway):
use std::sync::{Arc, Mutex};
use std::collections::LinkedList;
use std::os::unix::io::{RawFd, AsRawFd};
pub trait HRecv {}
pub trait HSend {}
pub trait HStream: HRecv + HSend + AsRawFd + CloneHStream {}
pub trait CloneHStream { fn clone_h_stream(&self) -> Box; }
impl CloneHStream for T where T: 'static + Clone + HStream {
fn clone_h_stream(&self) -> Box {
Box::new(self.clone())
}
}
pub struct Stream {
pub inner: Box
}
pub type StreamList = Arc>>;
fn main() {
let mut list = Arc::new(Mutex::new(LinkedList::::new()));
}