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: mod.rs
    path of file: ./repos/rio/sugarloaf/src/components/rich_text
    
    the code of the file until where you have to start completion: mod batch;
mod compositor;
mod image_cache;
pub mod text;
pub mod util;

use crate::components::core::orthographic_projection;
use crate::context::Context;
use crate::font::FontLibrary;
use crate::layout::SugarDimensions;
use compositor::{
    Command, Compositor, DisplayList, Rect, TextureEvent, TextureId, Vertex,
};
use fnv::FnvHashMap;
use std::{borrow::Cow, mem};
use text::{Glyph, TextRunStyle, UnderlineStyle};
use wgpu::util::DeviceExt;
use wgpu::Texture;

// Note: currently it's using Indexed drawing instead of Instance drawing could be worth to
// evaluate if would make sense move to instance drawing instead
// https://math.hws.edu/graphicsbook/c9/s2.html
// https://docs.rs/wgpu/latest/wgpu/enum.VertexStepMode.html

pub const BLEND: Option<wgpu::BlendState> = Some(wgpu::BlendState {
    color: wgpu::BlendComponent {
        src_factor: wgpu::BlendFactor::SrcAlpha,
        dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
        operation: wgpu::BlendOperation::Add,
    },
    alpha: wgpu::BlendComponent {
        src_factor: wgpu::BlendFactor::One,
        dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
        operation: wgpu::BlendOperation::Add,
    },
});

pub struct RichTextBrush {
    vertex_buffer: wgpu::Buffer,
    bind_group: wgpu::BindGroup,
    sampler: wgpu::Sampler,
    color_texture_view: wgpu::TextureView,
    mask_texture_view: wgpu::TextureView,
    transform: wgpu::Buffer,
    bind_group_layout: wgpu::BindGroupLayout,
    pipeline: wgpu::RenderPipeline,
    textures: FnvHashMap<TextureId, Texture>,
    index_buffer: wgpu::Buffer,
    index_buffer_size: u64,
    current_transform: [f32; 16],
    comp: Compositor,
    dlist: DisplayList,
    bind_group_needs_update: bool,
    first_run: bool,
    // selection: Selection,
    // selection_rects: Vec<[f32; 4]>,
    // selecting: bool,
    // selection_changed: bool,
    supported_vertex_buffer: usize,
}

impl RichTextBrush {
    pub fn new(context: &Context) -> Self {
  
    
    fn finish_composition(&mut self, ctx: &mut Context) {
        self.comp.finish(&mut self.dlist, |event| {
            match event {
                TextureEvent::CreateTexture {
                    id,
                    format,
                    width,
                    height,
                    data,
                } => {
                    log::info!(
                        "rich_text::CreateTexture with id ({:?}) and format {:?}",
                        id,
                        format
                    );
                    let texture_size = wgpu::Extent3d {
                        width: width.into(),
                        height: height.into(),
                        depth_or_array_layers: 1,
                    };
                    let texture = ctx.device.create_texture(&wgpu::TextureDescriptor {
                        size: texture_size,
                        mip_level_count: 1,
                        sample_count: 1,
                        dimension: wgpu::TextureDimension::D2,
                        format: match format {
                            image_cache::PixelFormat::A8 => wgpu::TextureFormat::R8Unorm,
                            image_cache::PixelFormat::Rgba8 => {
                                wgpu::TextureFormat::Rgba8Unorm
                            }
                        },
                        usage: wgpu::TextureUsages::TEXTURE_BINDING
                            | wgpu::TextureUsages::COPY_DST,
                        label: Some("rich_text::Cache"),
                        view_formats: &[],
                    });

                    if let Some(data) = data {
                        self.bind_group_needs_update = true;
                        let channels = match format {
                            // Mask
                            image_cache::PixelFormat::A8 => 1,
                            // Color
                            image_cache::PixelFormat::Rgba8 => 4,
                        };

                        ctx.queue.write_texture(
                            // Tells wgpu where to copy the pixel data
                            wgpu::ImageCopyTexture {
                                texture: &texture,
                                mip_level: 0,
                                origin: wgpu::Origin3d::ZERO,
                                aspect: wgpu::TextureAspect::All,
                            },
                            // The actual pixel data
                            data,
                            // The layout of the texture
                            wgpu::ImageDataLayout {
                                offset: 0,
                                bytes_per_row: Some((width * channels).into()),
                                rows_per_image: Some(height.into()),
                            },
                            texture_size,
                        );
                    }

                    self.textures.insert(id, texture);
                }
                TextureEvent::UpdateTexture {
                    id,
                    x,
                    y,
                    width,
                    height,
                    data,
                } => {
                    log::info!("rich_text::UpdateTexture id ({:?})", id);
                    if let Some(texture) = self.textures.get(&id) {
                        self.bind_group_needs_update = true;
                        let texture_size = wgpu::Extent3d {
                            width: width.into(),
                            height: height.into(),
                            depth_or_array_layers: 1,
                        };

                        // let channels = match format {
                        //     // Mask
                        //     image_cache::PixelFormat::A8 => 1,
                        //     // Color
                        //     image_cache::PixelFormat::Rgba8 => 4,
                        // };

                        ctx.queue.write_texture(
                            // Tells wgpu where to copy the pixel data
                            wgpu::ImageCopyTexture {
                                texture,
                                mip_level: 0,
                                origin: wgpu::Origin3d {
                                    x: u32::from(x),
                                    y: u32::from(y),
                                    z: 0,
                                },
                                aspect: wgpu::TextureAspect::All,
                            },
                            // The actual pixel data
                            data,
                            // The layout of the texture
                            wgpu::ImageDataLayout {
                                offset: 0,
                                bytes_per_row: Some((width * 4).into()),
                                rows_per_image: Some(height.into()),
                            },
                            texture_size,
                        );
                    }
                }
                TextureEvent::DestroyTexture(id) => {
                    log::info!("rich_text::DestroyTexture id ({:?})", id);
                    self.textures.remove(&id);
                }
            }
        });
    }