Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub trait A {
- fn method_a(&self) -> f64;
- }
- trait B<T> where T: A {
- fn method_b(&mut self) -> &Vec<T>;
- }
- trait GenericB {
- fn method_generic(&mut self) -> Vec<&A>;
- }
- impl<T> GenericB for B<T> where T: A {
- fn method_generic(&mut self) -> Vec<&A> {
- B::method_b(self).iter().map(
- |v| v as &A
- ).collect()
- }
- }
- struct Anon_a {
- pub x: f64
- }
- impl A for Anon_a {
- fn method_a(&self) -> f64 {
- self.x
- }
- }
- struct Anon_b {
- pub a: Option<Vec<Anon_a>>
- }
- impl B<Anon_a> for Anon_b {
- fn method_b(&mut self) -> &Vec<Anon_a> {
- self.a.as_ref().unwrap()
- }
- }
- fn main() {
- let b = Anon_b {
- a: Some(vec![Anon_a{x: 32.3}, Anon_a{x: 64.0}])
- };
- let c: Box<GenericB> = Box::new(b);
- }
Add Comment
Please, Sign In to add comment