Question 1: here's some code I wrote, and it compiles, but I wonder if it's possible to write these trait bounds less times than I did? The compiler doesn't require them in type declaration, but on docs.rs every type with generics does have them. Should I keep them there?
pub trait IntoDuration {};
pub struct RawEdge {};
pub struct WeightedEdge<S: IntoDuration> {
speed: S
}
impl<S: IntoDuration> WeightedEdge<S> {
pub fn from_raw(de: &RawEdge) -> Self {
todo!()
}
}
pub struct Graph<S: IntoDuration> {
edges: Vec<WeightedEdge<S>>,
}
impl<S: IntoDuration> Graph<S> {
// take denorm edge, convert
pub fn try_build<I>(&mut self, edges: I) -> Result<(), Box<dyn Error>> where I: Iterator<Item = RawEdge>, S: IntoDuration {
todo!()
}
}
Question 2: what to do if you need multiple traits and want to avoid repetition?
impl<'a, V: Copy + Hash + Eq, T: Clone> Iterator ...
// ^^^^^^^^^^^^^^^^^^^
// at least, maybe there's an alias for multiple traits?