You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: rebuild.rs
    path of file: ./repos/irisia-gui/irisia/src/dom/layer
    
    the code of the file until where you have to start completion: use anyhow::anyhow;
use irisia_backend::skia_safe::{colors::TRANSPARENT, Canvas};

use super::{LayerCompositer, SharedLayerCompositer};
use crate::Result;

pub struct LayerRebuilder<'a> {
    pub(super) lc: &'a mut LayerCompositer,
    pub(super) canvas: &'a mut Canvas,
    dirty: bool,
}

impl<'a> LayerRebuilder<'a> {
    pub(super) fn new(lc: &'a mut LayerCompositer, canvas: &'a mut Canvas) -> Self {
      
    
    fn flush(&mut self) -> Result<()> {
        if !self.dirty {
            return Ok(());
        }

        let bitmap = self.lc.layers.add_bitmap(&self.canvas.image_info());
        bitmap.alloc_pixels();
        if !self.canvas.read_pixels_to_bitmap(bitmap, (0, 0)) {
            self.lc.layers.pop();
            return Err(anyhow!("cannot flush canvas content"));
        }
        self.canvas.restore();
        self.dirty = false;

        Ok(())
    }