From 147da0b3a850f0820718a9cc37193bd75fb5dce3 Mon Sep 17 00:00:00 2001 From: Nazar Anroniuk Date: Fri, 15 Nov 2024 09:05:02 +0200 Subject: [PATCH] refactor: move the core functinality to the `core` module --- src-tauri/src/commands/pattern.rs | 6 ++++-- src-tauri/src/core/mod.rs | 2 ++ src-tauri/src/{ => core}/parser/embproj.rs | 2 +- src-tauri/src/{ => core}/parser/format.rs | 0 src-tauri/src/{ => core}/parser/mod.rs | 0 src-tauri/src/{ => core}/parser/oxs/mod.rs | 0 src-tauri/src/{ => core}/parser/oxs/oxs.rs | 2 +- src-tauri/src/{ => core}/parser/oxs/utils.rs | 0 src-tauri/src/{ => core}/parser/oxs/v1_0.rs | 2 +- src-tauri/src/{ => core}/parser/xsd/mod.rs | 0 .../src/{ => core}/parser/xsd/pmaker_floss_brands.json | 0 src-tauri/src/{ => core}/parser/xsd/read.rs | 0 src-tauri/src/{ => core}/parser/xsd/read.test.rs | 0 src-tauri/src/{ => core}/parser/xsd/xsd.rs | 2 +- src-tauri/src/{ => core}/parser/xsd/xsd.test.rs | 0 src-tauri/src/{ => core}/pattern/display.rs | 0 src-tauri/src/{ => core}/pattern/mod.rs | 0 src-tauri/src/{ => core}/pattern/pattern.rs | 0 src-tauri/src/{ => core}/pattern/print.rs | 0 src-tauri/src/{ => core}/pattern/project.rs | 0 src-tauri/src/{ => core}/pattern/stitches/fullstitch.rs | 2 +- src-tauri/src/{ => core}/pattern/stitches/line.rs | 2 +- src-tauri/src/{ => core}/pattern/stitches/mod.rs | 0 src-tauri/src/{ => core}/pattern/stitches/node.rs | 2 +- src-tauri/src/{ => core}/pattern/stitches/partstitch.rs | 2 +- src-tauri/src/{ => core}/pattern/stitches/special.rs | 2 +- src-tauri/src/{ => core}/pattern/stitches/stitches.rs | 0 src-tauri/src/{ => core}/pattern/stitches/stitches.test.rs | 0 src-tauri/src/events/pattern.rs | 2 +- src-tauri/src/lib.rs | 7 ++++--- src-tauri/src/state.rs | 2 +- 31 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 src-tauri/src/core/mod.rs rename src-tauri/src/{ => core}/parser/embproj.rs (97%) rename src-tauri/src/{ => core}/parser/format.rs (100%) rename src-tauri/src/{ => core}/parser/mod.rs (100%) rename src-tauri/src/{ => core}/parser/oxs/mod.rs (100%) rename src-tauri/src/{ => core}/parser/oxs/oxs.rs (97%) rename src-tauri/src/{ => core}/parser/oxs/utils.rs (100%) rename src-tauri/src/{ => core}/parser/oxs/v1_0.rs (99%) rename src-tauri/src/{ => core}/parser/xsd/mod.rs (100%) rename src-tauri/src/{ => core}/parser/xsd/pmaker_floss_brands.json (100%) rename src-tauri/src/{ => core}/parser/xsd/read.rs (100%) rename src-tauri/src/{ => core}/parser/xsd/read.test.rs (100%) rename src-tauri/src/{ => core}/parser/xsd/xsd.rs (99%) rename src-tauri/src/{ => core}/parser/xsd/xsd.test.rs (100%) rename src-tauri/src/{ => core}/pattern/display.rs (100%) rename src-tauri/src/{ => core}/pattern/mod.rs (100%) rename src-tauri/src/{ => core}/pattern/pattern.rs (100%) rename src-tauri/src/{ => core}/pattern/print.rs (100%) rename src-tauri/src/{ => core}/pattern/project.rs (100%) rename src-tauri/src/{ => core}/pattern/stitches/fullstitch.rs (97%) rename src-tauri/src/{ => core}/pattern/stitches/line.rs (97%) rename src-tauri/src/{ => core}/pattern/stitches/mod.rs (100%) rename src-tauri/src/{ => core}/pattern/stitches/node.rs (97%) rename src-tauri/src/{ => core}/pattern/stitches/partstitch.rs (98%) rename src-tauri/src/{ => core}/pattern/stitches/special.rs (96%) rename src-tauri/src/{ => core}/pattern/stitches/stitches.rs (100%) rename src-tauri/src/{ => core}/pattern/stitches/stitches.test.rs (100%) diff --git a/src-tauri/src/commands/pattern.rs b/src-tauri/src/commands/pattern.rs index 54c4b93..2145ab6 100644 --- a/src-tauri/src/commands/pattern.rs +++ b/src-tauri/src/commands/pattern.rs @@ -1,7 +1,9 @@ use crate::{ + core::{ + parser::{self, PatternFormat}, + pattern::{display::DisplaySettings, print::PrintSettings, PaletteItem, Pattern, PatternProject}, + }, error::CommandResult, - parser::{self, PatternFormat}, - pattern::{display::DisplaySettings, print::PrintSettings, PaletteItem, Pattern, PatternProject}, state::{AppStateType, PatternKey}, utils::path::app_document_dir, }; diff --git a/src-tauri/src/core/mod.rs b/src-tauri/src/core/mod.rs new file mode 100644 index 0000000..c67aa6d --- /dev/null +++ b/src-tauri/src/core/mod.rs @@ -0,0 +1,2 @@ +pub mod parser; +pub mod pattern; diff --git a/src-tauri/src/parser/embproj.rs b/src-tauri/src/core/parser/embproj.rs similarity index 97% rename from src-tauri/src/parser/embproj.rs rename to src-tauri/src/core/parser/embproj.rs index bb1ce0e..4f853bd 100644 --- a/src-tauri/src/parser/embproj.rs +++ b/src-tauri/src/core/parser/embproj.rs @@ -2,7 +2,7 @@ use std::io::Write; use anyhow::Result; -use crate::pattern::PatternProject; +use crate::core::pattern::PatternProject; pub fn parse_pattern(file_path: std::path::PathBuf) -> Result { log::info!("Parsing the EMBPROJ pattern file"); diff --git a/src-tauri/src/parser/format.rs b/src-tauri/src/core/parser/format.rs similarity index 100% rename from src-tauri/src/parser/format.rs rename to src-tauri/src/core/parser/format.rs diff --git a/src-tauri/src/parser/mod.rs b/src-tauri/src/core/parser/mod.rs similarity index 100% rename from src-tauri/src/parser/mod.rs rename to src-tauri/src/core/parser/mod.rs diff --git a/src-tauri/src/parser/oxs/mod.rs b/src-tauri/src/core/parser/oxs/mod.rs similarity index 100% rename from src-tauri/src/parser/oxs/mod.rs rename to src-tauri/src/core/parser/oxs/mod.rs diff --git a/src-tauri/src/parser/oxs/oxs.rs b/src-tauri/src/core/parser/oxs/oxs.rs similarity index 97% rename from src-tauri/src/parser/oxs/oxs.rs rename to src-tauri/src/core/parser/oxs/oxs.rs index 4fd54ac..e1b7e55 100644 --- a/src-tauri/src/parser/oxs/oxs.rs +++ b/src-tauri/src/core/parser/oxs/oxs.rs @@ -1,7 +1,7 @@ use anyhow::{bail, Result}; use quick_xml::events::Event; -use crate::pattern::PatternProject; +use crate::core::pattern::PatternProject; use super::{ utils::{process_attributes, OxsVersion, Software}, diff --git a/src-tauri/src/parser/oxs/utils.rs b/src-tauri/src/core/parser/oxs/utils.rs similarity index 100% rename from src-tauri/src/parser/oxs/utils.rs rename to src-tauri/src/core/parser/oxs/utils.rs diff --git a/src-tauri/src/parser/oxs/v1_0.rs b/src-tauri/src/core/parser/oxs/v1_0.rs similarity index 99% rename from src-tauri/src/parser/oxs/v1_0.rs rename to src-tauri/src/core/parser/oxs/v1_0.rs index 29e1198..964781d 100644 --- a/src-tauri/src/parser/oxs/v1_0.rs +++ b/src-tauri/src/core/parser/oxs/v1_0.rs @@ -8,7 +8,7 @@ use quick_xml::{ }; use super::utils::*; -use crate::pattern::{display::DisplaySettings, print::PrintSettings, *}; +use crate::core::pattern::{display::DisplaySettings, print::PrintSettings, *}; pub fn parse_pattern(file_path: std::path::PathBuf, software: Software) -> Result { log::trace!("OXS version is 1.0 in the {software:?} edition"); diff --git a/src-tauri/src/parser/xsd/mod.rs b/src-tauri/src/core/parser/xsd/mod.rs similarity index 100% rename from src-tauri/src/parser/xsd/mod.rs rename to src-tauri/src/core/parser/xsd/mod.rs diff --git a/src-tauri/src/parser/xsd/pmaker_floss_brands.json b/src-tauri/src/core/parser/xsd/pmaker_floss_brands.json similarity index 100% rename from src-tauri/src/parser/xsd/pmaker_floss_brands.json rename to src-tauri/src/core/parser/xsd/pmaker_floss_brands.json diff --git a/src-tauri/src/parser/xsd/read.rs b/src-tauri/src/core/parser/xsd/read.rs similarity index 100% rename from src-tauri/src/parser/xsd/read.rs rename to src-tauri/src/core/parser/xsd/read.rs diff --git a/src-tauri/src/parser/xsd/read.test.rs b/src-tauri/src/core/parser/xsd/read.test.rs similarity index 100% rename from src-tauri/src/parser/xsd/read.test.rs rename to src-tauri/src/core/parser/xsd/read.test.rs diff --git a/src-tauri/src/parser/xsd/xsd.rs b/src-tauri/src/core/parser/xsd/xsd.rs similarity index 99% rename from src-tauri/src/parser/xsd/xsd.rs rename to src-tauri/src/core/parser/xsd/xsd.rs index ec78b61..b2e3550 100644 --- a/src-tauri/src/parser/xsd/xsd.rs +++ b/src-tauri/src/core/parser/xsd/xsd.rs @@ -13,7 +13,7 @@ use byteorder::{LittleEndian, ReadBytesExt}; use ordered_float::NotNan; use super::read::ReadXsdExt; -use crate::pattern::{display::*, print::*, *}; +use crate::core::pattern::{display::*, print::*, *}; #[cfg(test)] #[path = "xsd.test.rs"] diff --git a/src-tauri/src/parser/xsd/xsd.test.rs b/src-tauri/src/core/parser/xsd/xsd.test.rs similarity index 100% rename from src-tauri/src/parser/xsd/xsd.test.rs rename to src-tauri/src/core/parser/xsd/xsd.test.rs diff --git a/src-tauri/src/pattern/display.rs b/src-tauri/src/core/pattern/display.rs similarity index 100% rename from src-tauri/src/pattern/display.rs rename to src-tauri/src/core/pattern/display.rs diff --git a/src-tauri/src/pattern/mod.rs b/src-tauri/src/core/pattern/mod.rs similarity index 100% rename from src-tauri/src/pattern/mod.rs rename to src-tauri/src/core/pattern/mod.rs diff --git a/src-tauri/src/pattern/pattern.rs b/src-tauri/src/core/pattern/pattern.rs similarity index 100% rename from src-tauri/src/pattern/pattern.rs rename to src-tauri/src/core/pattern/pattern.rs diff --git a/src-tauri/src/pattern/print.rs b/src-tauri/src/core/pattern/print.rs similarity index 100% rename from src-tauri/src/pattern/print.rs rename to src-tauri/src/core/pattern/print.rs diff --git a/src-tauri/src/pattern/project.rs b/src-tauri/src/core/pattern/project.rs similarity index 100% rename from src-tauri/src/pattern/project.rs rename to src-tauri/src/core/pattern/project.rs diff --git a/src-tauri/src/pattern/stitches/fullstitch.rs b/src-tauri/src/core/pattern/stitches/fullstitch.rs similarity index 97% rename from src-tauri/src/pattern/stitches/fullstitch.rs rename to src-tauri/src/core/pattern/stitches/fullstitch.rs index e4a20f3..4b2a5de 100644 --- a/src-tauri/src/pattern/stitches/fullstitch.rs +++ b/src-tauri/src/core/pattern/stitches/fullstitch.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use serde_repr::{Deserialize_repr, Serialize_repr}; use super::partstitch::*; -use crate::pattern::Coord; +use crate::core::pattern::Coord; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, BorshSerialize, BorshDeserialize)] pub struct FullStitch { diff --git a/src-tauri/src/pattern/stitches/line.rs b/src-tauri/src/core/pattern/stitches/line.rs similarity index 97% rename from src-tauri/src/pattern/stitches/line.rs rename to src-tauri/src/core/pattern/stitches/line.rs index 8ea5ec2..a9d0eb6 100644 --- a/src-tauri/src/pattern/stitches/line.rs +++ b/src-tauri/src/core/pattern/stitches/line.rs @@ -2,7 +2,7 @@ use borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; use serde_repr::{Deserialize_repr, Serialize_repr}; -use crate::pattern::Coord; +use crate::core::pattern::Coord; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, BorshSerialize, BorshDeserialize)] pub struct Line { diff --git a/src-tauri/src/pattern/stitches/mod.rs b/src-tauri/src/core/pattern/stitches/mod.rs similarity index 100% rename from src-tauri/src/pattern/stitches/mod.rs rename to src-tauri/src/core/pattern/stitches/mod.rs diff --git a/src-tauri/src/pattern/stitches/node.rs b/src-tauri/src/core/pattern/stitches/node.rs similarity index 97% rename from src-tauri/src/pattern/stitches/node.rs rename to src-tauri/src/core/pattern/stitches/node.rs index 4e181e3..954fd03 100644 --- a/src-tauri/src/pattern/stitches/node.rs +++ b/src-tauri/src/core/pattern/stitches/node.rs @@ -2,7 +2,7 @@ use borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; use serde_repr::{Deserialize_repr, Serialize_repr}; -use crate::pattern::Coord; +use crate::core::pattern::Coord; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, BorshSerialize, BorshDeserialize)] pub struct Node { diff --git a/src-tauri/src/pattern/stitches/partstitch.rs b/src-tauri/src/core/pattern/stitches/partstitch.rs similarity index 98% rename from src-tauri/src/pattern/stitches/partstitch.rs rename to src-tauri/src/core/pattern/stitches/partstitch.rs index c440de7..fa070b4 100644 --- a/src-tauri/src/pattern/stitches/partstitch.rs +++ b/src-tauri/src/core/pattern/stitches/partstitch.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use serde_repr::{Deserialize_repr, Serialize_repr}; use super::fullstitch::*; -use crate::pattern::Coord; +use crate::core::pattern::Coord; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, BorshSerialize, BorshDeserialize)] pub struct PartStitch { diff --git a/src-tauri/src/pattern/stitches/special.rs b/src-tauri/src/core/pattern/stitches/special.rs similarity index 96% rename from src-tauri/src/pattern/stitches/special.rs rename to src-tauri/src/core/pattern/stitches/special.rs index 4c0a983..a6504ca 100644 --- a/src-tauri/src/pattern/stitches/special.rs +++ b/src-tauri/src/core/pattern/stitches/special.rs @@ -2,7 +2,7 @@ use borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; use super::{Line, Node}; -use crate::pattern::Coord; +use crate::core::pattern::Coord; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, BorshSerialize, BorshDeserialize)] pub struct SpecialStitch { diff --git a/src-tauri/src/pattern/stitches/stitches.rs b/src-tauri/src/core/pattern/stitches/stitches.rs similarity index 100% rename from src-tauri/src/pattern/stitches/stitches.rs rename to src-tauri/src/core/pattern/stitches/stitches.rs diff --git a/src-tauri/src/pattern/stitches/stitches.test.rs b/src-tauri/src/core/pattern/stitches/stitches.test.rs similarity index 100% rename from src-tauri/src/pattern/stitches/stitches.test.rs rename to src-tauri/src/core/pattern/stitches/stitches.test.rs diff --git a/src-tauri/src/events/pattern.rs b/src-tauri/src/events/pattern.rs index bdd02a1..7b9e3d4 100644 --- a/src-tauri/src/events/pattern.rs +++ b/src-tauri/src/events/pattern.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use tauri::{AppHandle, Emitter, Listener, Manager, WebviewWindow}; use crate::{ - pattern::{Stitch, StitchConflicts}, + core::pattern::{Stitch, StitchConflicts}, state::{AppStateType, PatternKey}, }; diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index a72545e..98b70f8 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -2,8 +2,9 @@ mod error; pub mod commands; pub mod events; -pub mod logger; -pub mod parser; -pub mod pattern; pub mod state; + +pub mod core; pub mod utils; + +pub mod logger; diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rs index e2d026a..9fd7d1a 100644 --- a/src-tauri/src/state.rs +++ b/src-tauri/src/state.rs @@ -3,7 +3,7 @@ use std::{collections::HashMap, path::PathBuf}; use borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; -use crate::pattern::PatternProject; +use crate::core::pattern::PatternProject; #[derive(Debug, Hash, PartialEq, Eq, Clone, Serialize, Deserialize, BorshSerialize, BorshDeserialize)] #[repr(transparent)]