From 81a6ec22d01b004c15748f0245f3395f8649ea91 Mon Sep 17 00:00:00 2001 From: Alain Emilia Anna Zscheile Date: Fri, 6 Dec 2024 19:46:30 +0100 Subject: [PATCH] refactor(specctra-core): merge common.rs into lib.rs --- crates/specctra-core/src/common.rs | 25 ------------------------ crates/specctra-core/src/lib.rs | 31 ++++++++++++++++++++++++++---- crates/specctra-core/src/read.rs | 2 +- crates/specctra-core/src/write.rs | 2 +- 4 files changed, 29 insertions(+), 31 deletions(-) delete mode 100644 crates/specctra-core/src/common.rs diff --git a/crates/specctra-core/src/common.rs b/crates/specctra-core/src/common.rs deleted file mode 100644 index 282981a..0000000 --- a/crates/specctra-core/src/common.rs +++ /dev/null @@ -1,25 +0,0 @@ -pub enum ListToken { - Start { name: String }, - Leaf { value: String }, - End, -} - -impl ListToken { - pub fn is_start_of(&self, valid_names: &[&'static str]) -> bool { - if let Self::Start { name: actual_name } = self { - valid_names - .iter() - .any(|i| i.eq_ignore_ascii_case(actual_name)) - } else { - false - } - } - - pub fn len(&self) -> usize { - match &self { - Self::Start { name } => 1 + name.len(), - Self::Leaf { value } => value.len(), - Self::End => 1, - } - } -} diff --git a/crates/specctra-core/src/lib.rs b/crates/specctra-core/src/lib.rs index 383ef7d..79a7ecf 100644 --- a/crates/specctra-core/src/lib.rs +++ b/crates/specctra-core/src/lib.rs @@ -1,8 +1,5 @@ -//! Module containing the informations about handling the Specctra -//! based file format, and parsing it into Topola's objects +//! Module about handling the Specctra based file format, and parsing + serializing it -mod common; -pub use common::*; pub mod error; pub mod math; pub mod mesadata; @@ -10,3 +7,29 @@ pub mod read; pub mod rules; pub mod structure; pub mod write; + +pub enum ListToken { + Start { name: String }, + Leaf { value: String }, + End, +} + +impl ListToken { + pub fn is_start_of(&self, valid_names: &[&'static str]) -> bool { + if let Self::Start { name: actual_name } = self { + valid_names + .iter() + .any(|i| i.eq_ignore_ascii_case(actual_name)) + } else { + false + } + } + + pub fn len(&self) -> usize { + match &self { + Self::Start { name } => 1 + name.len(), + Self::Leaf { value } => value.len(), + Self::End => 1, + } + } +} diff --git a/crates/specctra-core/src/read.rs b/crates/specctra-core/src/read.rs index ceffd2a..0caebff 100644 --- a/crates/specctra-core/src/read.rs +++ b/crates/specctra-core/src/read.rs @@ -1,6 +1,6 @@ -use super::common::ListToken; use super::error::{ParseError, ParseErrorContext}; use super::structure::Parser; +use super::ListToken; use utf8_chars::BufReadCharsExt; pub struct InputToken { diff --git a/crates/specctra-core/src/write.rs b/crates/specctra-core/src/write.rs index 7b12302..c77c12f 100644 --- a/crates/specctra-core/src/write.rs +++ b/crates/specctra-core/src/write.rs @@ -1,4 +1,4 @@ -use super::common::ListToken; +use super::ListToken; use std::io; pub trait WriteSes {