Now that we know a little bit about trait objects and how to work with them, let's use them in a different example, this challenge focuses on using Box<dyn Trait> as fields in structs to encapsulate objects with dynamic behavior.
You need to define a trait called Renderable and create two structs, Circle and Rectangle, that implement this trait. Then, you will create another struct called Canvas, which can hold a collection of objects implementing the Renderable trait. The Canvas struct should have methods to add objects and render all objects.
Here are the requirements for the program, make sure to read them carefully:
Renderable Traitrender(&self) -> String to represent the object visually.Circle and Rectangle StructsCircle should have a radius: f64 field.Rectangle should have width: f64 and height: f64 fields.Renderable TraitCircle, the render method should return a string like "Circle with radius X".Rectangle, the render method should return a string like "Rectangle with width X and height Y".Canvas Structshapes field that can store a Vec of the Renderable trait objects.Canvas:
new() -> Canvas: Initializes an empty canvas.add_shape(): Adds a shape to the canvas.render_all(): Returns a vector of strings, each representing a rendered shape.⚠️ Make sure you make all the relevant items public with the pub keyword, this is required for the tests to work.
If you're stuck, here are some hints to help you solve the challenge:
Box<dyn Trait> to store objects with dynamic behavior. e.g.
pub struct Canvas {
  pub shapes: Vec<Box<dyn Renderable>>,
}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}// 2. Create the Canvas struct#[derive(Default)]pub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Self {        Self::default()    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|shape| shape.render()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Self {        Canvas{shapes: Vec::new()}    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|s| s.render()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Self {        Canvas { shapes: Vec::new() }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|x| x.render()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}// 2. Create the Canvas structpub struct Canvas {    shapes: Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Self {        Canvas { shapes: vec![] }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape)    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|shape| shape.render()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self)-> String{        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}",self.width,self.height)    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Canvas {        Canvas { shapes: Vec::new() }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>){        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        return self.shapes.iter().map(|shape| shape.render()).collect();    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}impl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!(            "Rectangle with width {} and height {}",            self.width, self.height        )    }}pub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}impl Canvas {    pub fn new() -> Canvas {        Canvas { shapes: Vec::new() }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|shape| shape.render()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius).to_string()     }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self. height).to_string()     }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>, }// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Canvas {        Canvas{shapes: Vec::<Box<dyn Renderable>>::new()}    }    pub fn add_shape(&mut self, a:Box<dyn Renderable>) {        self.shapes.push(a);     }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|b| {(*b).render()}).collect() // *b same to just b    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle{    fn render(&self) -> String{        format!("Circle with radius {}",self.radius)    }}impl Renderable for Rectangle{    fn render(&self) -> String{        format!("Rectangle with width {} and height {}", self.width , self.height)    }}// 2. Create the Canvas structpub struct Canvas{    pub shapes : Vec<Box<dyn Renderable>>}// 3. Implement the Canvas structimpl Canvas{    pub fn new() -> Canvas{        Canvas{            shapes : Vec::new(),        }    }    pub fn add_shape(&mut self ,shape : Box<dyn Renderable>){        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String>{        let mut resvec : Vec<String> = Vec::new();        for shape in self.shapes.iter(){            resvec.push(shape.render());        }        resvec    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!(            "Rectangle with width {} and height {}",            self.width, self.height        )    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Canvas {        Canvas { shapes: vec![] }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape)    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|shape| shape.render()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!(            "Rectangle with width {} and height {}",            self.width, self.height        )    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Canvas {        Canvas { shapes: vec![] }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape)    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|shape| shape.render()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>}impl Canvas {    pub fn new() -> Canvas {        Canvas{ shapes: Vec::new()}    }    pub fn add_shape(&mut self,item: Box<dyn Renderable>) {        self.shapes.push(item)    }    pub fn render_all(&self) -> Vec<String> {        let mut a = Vec::new();        for i in self.shapes.iter() {            a.push(i.render())        }        a    }}// 3. Implement the Canvas struct// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle{    fn render(&self) -> String{        format!("Circle with radius {}",self.radius)    }}impl Renderable for Rectangle{    fn render(&self) -> String{        format!("Rectangle with width {} and height {}",self.width, self.height)    }}// 2. Create the Canvas structpub struct Canvas{    pub shapes : Vec<Box<dyn Renderable>>}// 3. Implement the Canvas structimpl Canvas{    pub fn new() -> Canvas{        Canvas{shapes: Vec::new()}    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>){        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String>{        let mut string_vec:Vec<String> = Vec::new();        for shape in self.shapes.iter(){            string_vec.push(shape.render());        }        string_vec    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}impl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!(            "Rectangle with width {} and height {}",            self.width, self.height        )    }}#[derive(Default)]pub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}impl Canvas {    pub fn new() -> Self {        Canvas { shapes: vec![] }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes            .iter()            .map(|shape| shape.render().to_string())            .collect()    }}pub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}impl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!(            "Rectangle with width {} and height {}",            self.width, self.height        )    }}#[derive(Default)]pub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}impl Canvas {    pub fn new() -> Self {        Canvas { shapes: vec![] }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|shape| shape.render()).collect()    }}pub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!(            "Rectangle with width {} and height {}",            self.width, self.height        )    }}// 2. Create the Canvas structpub struct Canvas {    shapes: Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Self {        Canvas { shapes: vec![] }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|item| item.render()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}use std::fmt::Display;pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width,self.height)    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}impl Display for dyn Renderable {    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {        write!(f, "{}", self.render())    }}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Canvas {        Canvas { shapes: vec![] }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {    self.shapes.iter().map(|shape| shape.render()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}impl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!(            "Rectangle with width {} and height {}",            self.width, self.height        )    }}pub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}impl Canvas {    pub fn new() -> Canvas {        Canvas { shapes: vec![] }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|x| x.render()).collect()    }}pub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Canvas {        Canvas {            shapes: Vec::new(),        }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        let render = self.shapes                        .iter()                        .map(|shape| shape.render())                        .collect::<Vec<String>>();        render    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}",self.radius)    } }impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}",self.width,self.height)    }}// 2. Create the Canvas structpub struct Canvas {    pub shape:Vec<Box<dyn Renderable>>}// 3. Implement the Canvas structimpl Canvas {    pub fn new()->Self{        Canvas { shape: Vec::new() }    }    pub fn add_shape(&mut self,shape:Box<dyn Renderable>) {        self.shape.push(shape);    }    pub fn render_all(&self)->Vec<String>{        let mut render = Vec::new();        for i in &self.shape{            render.push(i.render());        }        render    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}",self.radius)    }    }impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}",self.width,self.height)    }}// 2. Create the Canvas structpub struct Canvas {   pub shapes:Vec<Box<dyn Renderable>>}impl Canvas {   pub fn new()->Self{        Canvas { shapes: Vec::new() }    }   pub  fn add_shape(&mut self,shape:Box<dyn Renderable>) {        self.shapes.push(shape);    }   pub  fn render_all(&self)-> Vec<String>{        let mut  render = Vec::new();         for i in &self.shapes{            render.push(i.render());         }         render            }    }// 3. Implement the Canvas struct// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        String::from(format!("Circle with radius {}", self.radius))    }}impl Renderable for Rectangle {    fn render(&self) -> String {        String::from(format!("Rectangle with width {} and height {}", self.width, self.height))    }}// 2. Create the Canvas structpub struct Canvas {    shapes: Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Self {        Canvas {            shapes: vec![]        }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape)    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|object: &Box<dyn Renderable>| object.render()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Canvas {        Canvas {            shapes: Vec::<Box<dyn Renderable>>::new(),        }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|object: &Box<dyn Renderable>| object.render()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Canvas {        Canvas { shapes: Vec::<Box<dyn Renderable>>::new() }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|r: &Box<dyn Renderable>| r.render()).collect()        // self.shapes.iter().map(|r| r.render()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Canvas {        Canvas { shapes: Vec::<Box<dyn Renderable>>::new() }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|r: &Box<dyn Renderable>| r.as_ref().render()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String{                format!("Circle with radius {}", self.radius)   }}impl Renderable for Rectangle {    fn render(&self) -> String{        format!("Rectangle with width {} and height {}", self.width, self.height)            }}// 2. Create the Canvas structpub struct Canvas {    shapes: Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Canvas {        Canvas {            shapes: Vec::new(),        }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|s| s.render()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait  Renderable {    fn render(&self) -> String {        "This is render from Renderable".to_string()    }}#[derive(Clone)]pub struct Circle {    pub radius: f64,}impl Renderable for Circle {    fn render(&self) -> String {       format!("Circle with radius {}", self.radius)    }}#[derive(Clone)]pub struct  Rectangle {    pub width: f64,    pub height: f64}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}// #[derive(Clone)]pub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>}impl Canvas {    pub fn new() -> Self {        Self { shapes: Vec::new() }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        let res = self.shapes.iter().map(|el| {            el.render()        }).collect();        res    }}// 1. Implement the trait for Circle and Rectangle// 2. Create the Canvas struct// 3. Implement the Canvas struct// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}// 2. Create the Canvas structimpl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}pub struct Canvas {    shapes: Vec<Box<dyn Renderable>>}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Canvas {        Canvas { shapes: vec![] }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|shape| {            shape.render()        }).collect()    }    }// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}impl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}pub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}impl Canvas {    pub fn new() -> Self {        Self {            shapes: Vec::new(),        }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|shape| shape.render()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius).into()    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height).into()    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Self {        Self{            shapes: Vec::new(),        }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|x| x.render().into()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius).into()    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height).into()    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Self {        Self{            shapes: Vec::new(),        }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|x| x.render()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle{    fn render(&self) -> String {        return format!("Circle with radius {}",self.radius);    }}impl Renderable for Rectangle{    fn render(&self) -> String {        return format!("Rectangle with width {} and height {}",self.width,self.height);    }}// 2. Create the Canvas structpub struct Canvas {    shapes : Vec<Box<dyn Renderable>>}// 3. Implement the Canvas structimpl Canvas{    pub fn new() -> Canvas{        return Canvas{ shapes: Vec::new()};    }    pub fn add_shape(&mut self , shape : Box<dyn Renderable>){        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        return self.shapes.iter().map(|shp| shp.render()).collect();    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangle impl Renderable for Circle {    fn render (&self)-> String{   format!("Circle with radius {}",{self.radius})    } } impl Renderable for Rectangle {    fn render (&self)-> String{        format!("Rectangle with width {} and height {}", {self.width},{self.height})       } }// 2. Create the Canvas structpub struct Canvas{    pub shapes : Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {   pub fn new()-> Canvas{       Canvas {        shapes :  Vec::new(),       }     }    pub fn add_shape (& mut self, shape:Box<dyn Renderable>){        self.shapes.push(shape);               }    pub fn render_all(&self) -> Vec<String>{        self.shapes.iter().map(|x| x.render()).collect()    } }// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangle impl Renderable for Circle {    fn render (&self)-> String{   format!("Circle with radius {}",{self.radius})    } } impl Renderable for Rectangle {    fn render (&self)-> String{        format!("Rectangle with width {} and height {}", {self.width},{self.height})       } }// 2. Create the Canvas structpub struct Canvas{    pub shapes : Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {   pub fn new()-> Canvas{       Canvas {        shapes :  Vec::new(),       }     }    pub fn add_shape (& mut self, shape:Box<dyn Renderable>){        self.shapes.push(shape);               }    pub fn render_all(&self) -> Vec<String>{        self.shapes.iter().map(|x| x.render()).collect()    } }// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle{    fn render(&self) -> String{        format!("Circle with radius {}",self.radius)    }}impl Renderable for Rectangle{    fn render(&self) -> String{        format!("Rectangle with width {} and height {}",self.width, self.height)    }}// 2. Create the Canvas structpub struct Canvas{    pub shapes : Vec::<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas{    pub fn new() -> Self{        Self{            shapes : vec![]        }    }    pub fn add_shape(&mut self, shape : Box<dyn Renderable>){        self.shapes.push(shape);               }    pub fn render_all(&self) -> Vec<String>{        self.shapes.iter().map(|x| x.render()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}impl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!(            "Rectangle with width {} and height {}",            self.width, self.height        )    }}pub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}impl Canvas {    pub fn new() -> Self {        Self { shapes: Vec::new() }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|shape| shape.render()).collect()    }}// 3. Implement the Canvas struct// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}impl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}pub struct Canvas {  pub shapes: Vec<Box<dyn Renderable>>,}impl Canvas {    pub fn new() -> Self {        Canvas {            shapes: Vec::new(),        }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape)    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|v| v.render()).collect()    }}// 1. Implement the trait for Circle and Rectangle// 2. Create the Canvas struct// 3. Implement the Canvas struct// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Canvas {        Canvas{shapes: Vec::new()}    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|s| s.render()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)        }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)        }}// 2. Create the Canvas structpub struct Canvas {    pub shapes : Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Self {        Canvas {            shapes : Vec::new(),        }    }    pub fn add_shape(&mut self, shape : Box<dyn Renderable>) {        self.shapes.push(shape)    }    pub fn render_all(&self) -> Vec<String>{        let mut all_shapes = vec![];        for elem in self.shapes.iter() {            all_shapes.push(elem.render());        }        all_shapes    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}impl Canvas {    pub fn new() -> Self {        Self{shapes: vec![]}    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {              self.shapes.iter().map(|s| s.render()).collect()            }}// 3. Implement the Canvas struct// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}impl Canvas {    pub fn new() -> Self {        Self{shapes: vec![]}    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        let mut v: Vec<String> = Vec::new();        for s in self.shapes.iter(){            v.push(s.render());        }        v    }}// 3. Implement the Canvas struct// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle{    fn render(&self) -> String{        format!("Circle with radius {}",self.radius)    }}impl Renderable for Rectangle{    fn render(&self) -> String{        format!("Rectangle with width {} and height {}",self.width, self.height)    }}// 2. Create the Canvas structpub struct Canvas{    pub shapes: Vec<Box<dyn Renderable>>}// 3. Implement the Canvas structimpl Canvas{    pub fn new() -> Self{        Canvas{            shapes: Vec::new()        }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>){        self.shapes.push(shape)    }    pub fn render_all(&self) -> Vec<String>{        self.shapes.iter().map(|shape|shape.render()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle{    fn render(&self) -> String{        return format!("Circle with radius {}",self.radius).into();    }}impl Renderable for Rectangle{    fn render(&self) -> String{        return format!("Rectangle with width {} and height {}",self.width,self.height).into();    }}// 2. Create the Canvas structpub struct Canvas{    pub shapes: Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas{    pub fn new() -> Self{        Canvas{            shapes: Vec::new(),        }    }    pub fn add_shape(&mut self, new_shape: Box<dyn Renderable>){        self.shapes.push(new_shape);    }    pub fn render_all(&self) -> Vec<String>{        let mut allStrings:Vec<String> = Vec::new();        for shape in &self.shapes{            allStrings.push(shape.render());        }        return allStrings;    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Self { Canvas { shapes: vec![] }}    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|elem| elem.render().to_string()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Self { Canvas { shapes: vec![] }}    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|elem| elem.render()).collect::<Vec<String>>()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}",self.radius)    }}impl Renderable for Rectangle{    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes : Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new()->Self {        Self {shapes : Vec::new()}    }    pub fn add_shape(&mut self, shape : Box<dyn Renderable>){        self.shapes.push(shape);    }    pub fn render_all(&self)-> Vec<String>{        self.shapes.iter().map(|shape| shape.render()).collect::<Vec<String>>()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Self {        Self {            shapes: Vec::new()        }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape)    }    pub fn render_all(&self) -> Vec<String> {        let mut rendered = Vec::new();        for x in &self.shapes {            rendered.push(x.render())        }        rendered    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}impl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!(            "Rectangle with width {} and height {}",            self.width, self.height        )    }}pub struct Canvas {    shapes: Vec<Box<dyn Renderable>>,}impl Canvas {    pub fn new() -> Self {        Self { shapes: Vec::new() }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|shape| shape.render()).collect()    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}// 2. Create the Canvas structpub struct Canvas {    shapes: Vec<Box<dyn Renderable>>,}// 3. Implement the Canvas structimpl Canvas {    pub fn new() -> Self {        Self { shapes: Vec::new() }    }    pub fn add_shape(&mut self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map(|shape| shape.render()).collect()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(self: &Self) -> String {        format!("Circle with radius {0}", self.radius)    }}impl Renderable for Rectangle {    fn render(self: &Self) -> String {        format!("Rectangle with width {0} and height {1}", self.width, self.height)    }}// 2. Create the Canvas structpub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>}impl Canvas {    pub fn new() -> Self {        Canvas{            shapes: Vec::new()        }    }    pub fn add_shape(self: &mut Self, shape: Box<dyn Renderable>) {        self.shapes.push(shape);    }    pub fn render_all(self: &Self) -> Vec<String> {        self.shapes.iter().map(|s| s.render()).collect()    }}// 3. Implement the Canvas struct// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}pub trait Renderable {    fn render(&self) -> String;}pub struct Circle {    pub radius: f64,}pub struct Rectangle {    pub width: f64,    pub height: f64,}// 1. Implement the trait for Circle and Rectangleimpl Renderable for Circle {    fn render(&self) -> String {        format!("Circle with radius {}", self.radius)    }}impl Renderable for Rectangle {    fn render(&self) -> String {        format!("Rectangle with width {} and height {}", self.width, self.height)    }}pub struct Canvas {    pub shapes: Vec<Box<dyn Renderable>>}impl Canvas {    pub fn new() -> Self {        Self{shapes: vec![] }    }    pub fn add_shape(&mut self, b: Box<dyn Renderable>)    {        self.shapes.push(b);    }    pub fn render_all(&self) -> Vec<String> {        self.shapes.iter().map( |x| x.render() ).collect::<Vec<String>>()    }}// Example usagepub fn main() {    let mut canvas = Canvas::new();    canvas.add_shape(Box::new(Circle { radius: 5.0 }));    canvas.add_shape(Box::new(Rectangle {        width: 3.0,        height: 4.0,    }));    let rendered_shapes = canvas.render_all();    for shape in rendered_shapes {        println!("{}", shape);    }}