diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-02-27 06:16:23 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-02-27 06:16:23 +0800 |
| commit | 748c8a3353df887ee4b01e0e1327aa95c1c7225a (patch) | |
| tree | ab84ee3fd6af53e8b03e73f9bdc5177f10606e4a /systems/sheet/src/sheet.rs | |
| parent | 53141f612ab43136b4b1db7406ac71bb97284460 (diff) | |
Add remote flag to IndexSource and parsing support
Diffstat (limited to 'systems/sheet/src/sheet.rs')
| -rw-r--r-- | systems/sheet/src/sheet.rs | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/systems/sheet/src/sheet.rs b/systems/sheet/src/sheet.rs index 07d284b..e7a130d 100644 --- a/systems/sheet/src/sheet.rs +++ b/systems/sheet/src/sheet.rs @@ -13,7 +13,7 @@ use crate::{ index_source::IndexSource, mapping::{LocalMapping, LocalMappingForward, Mapping, MappingBuf}, sheet::{ - error::{ReadSheetDataError, SheetApplyError, SheetEditError}, + error::{ParseSheetError, ReadSheetDataError, SheetApplyError, SheetEditError}, reader::{read_mapping, read_sheet_data}, writer::convert_sheet_data_to_bytes, }, @@ -486,6 +486,42 @@ impl SheetData { } } +impl std::fmt::Display for SheetData { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let mut vec = self + .mappings() + .iter() + .cloned() + .collect::<Vec<LocalMapping>>(); + vec.sort(); + write!( + f, + "{}", + vec.iter() + .map(|m| m.to_string()) + .collect::<Vec<_>>() + .join("\n") + ) + } +} + +impl TryFrom<&str> for SheetData { + type Error = ParseSheetError; + + fn try_from(value: &str) -> Result<Self, Self::Error> { + let mut sheet = SheetData::empty().pack("temp"); + for line in value.split("\n") { + if line.trim().is_empty() { + continue; + } + let mapping = LocalMapping::try_from(line)?; + let _ = sheet.insert_mapping(mapping)?; + } + let _ = sheet.apply()?; + Ok(sheet.unpack()) + } +} + impl From<SheetData> for Vec<u8> { fn from(value: SheetData) -> Self { value.as_bytes() |
