use std::sync::mpsc::{Sender, Receiver};
pub struct Transport<T> {
sender: std::sync::mpsc::Sender<T>,
recver: std::sync::mpsc::Receiver<T>,
}
pub struct App<T>{
name: String,
transport: Option<Transport<T>>
}
impl <T> App <T> {
pub fn new(name: String) -> App<T> {
App { name, transport: None }
}
pub fn with_transport(name: String, t: Transport<T>) -> App<T> {
App { name, transport: Some(t) }
}
}
fn main()
{
let name = String::from("myapp");
let app = App::new(name);
}
This results in an error that app needs a type, however, I think it would be convenient if the user didn't have to specify a type unless they were using a transport. Ideally, the user would call App::new() to create an app without a transport and App::with_transport() to create an app with a transport. Is this possible or is there a better way?