From 4a1117366193281394f7e42fa297d41639385899 Mon Sep 17 00:00:00 2001 From: Hector van der Aa <103751865+H3ct0r55@users.noreply.github.com> Date: Wed, 3 Dec 2025 21:51:58 +0100 Subject: [PATCH] Refactor config into submodules --- src/config/mod.rs | 5 ++++ src/config/stream.rs | 44 +++++++++++++++++++++++++++ src/{config.rs => config/version.rs} | 45 +++------------------------- 3 files changed, 53 insertions(+), 41 deletions(-) create mode 100644 src/config/mod.rs create mode 100644 src/config/stream.rs rename src/{config.rs => config/version.rs} (79%) diff --git a/src/config/mod.rs b/src/config/mod.rs new file mode 100644 index 0000000..c34166a --- /dev/null +++ b/src/config/mod.rs @@ -0,0 +1,5 @@ +pub mod stream; +pub mod version; + +pub use stream::{StreamLine, StreamSource}; +pub use version::{MinecraftType, MinecraftVersion, Snapshot, Version}; diff --git a/src/config/stream.rs b/src/config/stream.rs new file mode 100644 index 0000000..3b1b6f2 --- /dev/null +++ b/src/config/stream.rs @@ -0,0 +1,44 @@ +use std::fmt::{self, Display}; + +/// Identifies which process stream produced a line of output. +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum StreamSource { + Stdout, + Stderr, +} + +/// Captures a single line of process output along with its origin stream. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct StreamLine { + line: String, + source: StreamSource, +} + +impl StreamLine { + pub fn new>(line: S, source: StreamSource) -> Self { + Self { + line: line.into(), + source, + } + } + + pub fn stdout>(line: S) -> Self { + Self { + line: line.into(), + source: StreamSource::Stdout, + } + } + + pub fn stderr>(line: S) -> Self { + Self { + line: line.into(), + source: StreamSource::Stderr, + } + } +} + +impl Display for StreamLine { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.line) + } +} diff --git a/src/config.rs b/src/config/version.rs similarity index 79% rename from src/config.rs rename to src/config/version.rs index 842bbcc..982d74c 100644 --- a/src/config.rs +++ b/src/config/version.rs @@ -5,11 +5,13 @@ use std::{ use crate::error::VersionError; +/// Identifies the type of Minecraft distribution supported by the configuration. #[derive(Debug, Clone, PartialEq, Eq)] pub enum MinecraftType { Vanilla, } +/// Semantic release version parsed from strings like `1.20.4`. #[derive(Debug, Clone, PartialEq, Eq)] pub struct Version { pub major: u32, @@ -17,6 +19,7 @@ pub struct Version { pub patch: u32, } +/// Snapshot version parsed from strings like `23w13b`. #[derive(Debug, Clone, PartialEq, Eq)] pub struct Snapshot { pub year: u32, @@ -24,24 +27,13 @@ pub struct Snapshot { pub build: char, } +/// Enum covering both release and snapshot Minecraft version formats. #[derive(Debug, Clone, PartialEq, Eq)] pub enum MinecraftVersion { Release(Version), Snapshot(Snapshot), } -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum StreamSource { - Stdout, - Stderr, -} - -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct StreamLine { - line: String, - source: StreamSource, -} - impl Display for Version { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}.{}.{}", self.major, self.minor, self.patch) @@ -136,32 +128,3 @@ impl FromStr for MinecraftVersion { Err(VersionError::UnknownVersionFormat(s.to_string())) } } - -impl StreamLine { - pub fn new>(line: S, source: StreamSource) -> Self { - Self { - line: line.into(), - source, - } - } - - pub fn stdout>(line: S) -> Self { - Self { - line: line.into(), - source: StreamSource::Stdout, - } - } - - pub fn stderr>(line: S) -> Self { - Self { - line: line.into(), - source: StreamSource::Stderr, - } - } -} - -impl Display for StreamLine { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.line) - } -}