umya-spreadsheet 3.0.0

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

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

use super::{
    super::super::{
        EnumValue,
        StringValue,
    },
    SystemColorValues,
};
use crate::{
    reader::driver::{
        get_attribute,
        set_string_from_xml,
        xml_read_loop,
    },
    writer::driver::write_start_tag,
};

#[derive(Clone, Default, Debug)]
pub struct SystemColor {
    val:        EnumValue<SystemColorValues>,
    last_color: StringValue,
}

impl SystemColor {
    #[inline]
    #[must_use]
    pub fn val(&self) -> &SystemColorValues {
        self.val.value()
    }

    #[inline]
    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use val()")]
    pub fn get_val(&self) -> &SystemColorValues {
        self.val()
    }

    #[inline]
    pub fn set_val(&mut self, value: SystemColorValues) -> &mut Self {
        self.val.set_value(value);
        self
    }

    #[inline]
    #[must_use]
    pub fn last_color(&self) -> &str {
        self.last_color.value_str()
    }

    #[inline]
    #[must_use]
    #[deprecated(since = "3.0.0", note = "Use last_color()")]
    pub fn get_last_color(&self) -> &str {
        self.last_color()
    }

    #[inline]
    pub fn set_last_color<S: Into<String>>(&mut self, value: S) {
        self.last_color.set_value(value.into());
    }

    #[inline]
    pub(crate) fn set_attributes<R: std::io::BufRead>(
        &mut self,
        reader: &mut Reader<R>,
        e: &BytesStart,
        empty_flag: bool,
    ) {
        set_string_from_xml!(self, e, val, "val");
        set_string_from_xml!(self, e, last_color, "lastClr");

        if empty_flag {
            return;
        }

        xml_read_loop!(
            reader,
            Event::End(ref e) => {
                if e.name().into_inner() == b"a:sysClr" {
                    return;
                }
            },
            Event::Eof => panic!("Error: Could not find {} end element", "a:sysClr")
        );
    }

    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
        // a:srgbClr
        let mut attributes: crate::structs::AttrCollection = Vec::new();
        let val = self.val.value_string();
        if self.val.has_value() {
            attributes.push(("val", val).into());
        }
        let last_color = self.last_color.value_str();
        if self.last_color.has_value() {
            attributes.push(("lastClr", last_color).into());
        }
        write_start_tag(writer, "a:sysClr", attributes, true);
    }
}