umya-spreadsheet 3.0.0

umya-spreadsheet is a library written in pure Rust to read and write xlsx file.
Documentation
// colors
use std::io::Cursor;

use quick_xml::{
    Reader,
    Writer,
    events::{
        BytesStart,
        Event,
    },
};

use super::MruColors;
use crate::{
    reader::driver::xml_read_loop,
    writer::driver::{
        write_end_tag,
        write_start_tag,
    },
};

#[derive(Clone, Default, Debug)]
pub(crate) struct Colors {
    mru_colors: MruColors,
}

impl Colors {
    #[inline]
    pub(crate) fn mru_colors(&self) -> &MruColors {
        &self.mru_colors
    }

    #[inline]
    #[deprecated(since = "3.0.0", note = "Use mru_colors()")]
    pub(crate) fn get_mru_colors(&self) -> &MruColors {
        self.mru_colors()
    }

    #[inline]
    pub(crate) fn mru_colors_mut(&mut self) -> &mut MruColors {
        &mut self.mru_colors
    }

    #[inline]
    #[deprecated(since = "3.0.0", note = "Use mru_colors_mut()")]
    pub(crate) fn get_mru_colors_mut(&mut self) -> &mut MruColors {
        self.mru_colors_mut()
    }

    #[inline]
    pub(crate) fn set_mru_colors(&mut self, value: MruColors) -> &mut Self {
        self.mru_colors = value;
        self
    }

    pub(crate) fn set_attributes<R: std::io::BufRead>(
        &mut self,
        reader: &mut Reader<R>,
        _e: &BytesStart,
    ) {
        xml_read_loop!(
            reader,
            Event::Start(ref e) => {
                if e.name().into_inner() == b"mruColors" {
                    self.mru_colors.set_attributes(reader, e);
                }
            },
            Event::End(ref e) => {
                if e.name().into_inner() == b"colors" {
                    return
                }
            },
            Event::Eof => panic!("Error: Could not find {} end element", "colors")
        );
    }

    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
        if self.mru_colors.color().is_empty() {
            return;
        }
        // colors
        write_start_tag(writer, "colors", vec![], false);

        // mruColors
        self.mru_colors.write_to(writer);

        write_end_tag(writer, "colors");
    }
}