rizzoo 0.6.9

a cross platform color generation tool implementing Material 3 Expressive
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::color::types::ColorScheme;
use crate::error::LRatio;
use crate::paths::Paths;

pub fn write(paths: &Paths, scheme: &ColorScheme) -> Result<(), LRatio> {
    let json = serde_json::to_string_pretty(scheme)
        .map_err(|e| LRatio::ColorsJsonWrite(paths.output.clone(), e.to_string()))?;
    std::fs::write(&paths.output, json)
        .map_err(|e| LRatio::ColorsJsonWrite(paths.output.clone(), e.to_string()))?;
    Ok(())
}

pub fn read(paths: &Paths) -> Result<ColorScheme, LRatio> {
    let contents = std::fs::read_to_string(&paths.output)
        .map_err(|e| LRatio::CacheRead(paths.output.clone(), e.to_string()))?;
    serde_json::from_str(&contents).map_err(|_| LRatio::CacheCorrupted(paths.output.clone()))
}