Merge pull request #2 from H3ct0r55/codex/refactor-src/config.rs-into-submodules

Refactor config module into focused submodules
This commit is contained in:
Hector van der Aa
2025-12-03 21:52:15 +01:00
committed by GitHub
3 changed files with 53 additions and 41 deletions

5
src/config/mod.rs Normal file
View File

@@ -0,0 +1,5 @@
pub mod stream;
pub mod version;
pub use stream::{StreamLine, StreamSource};
pub use version::{MinecraftType, MinecraftVersion, Snapshot, Version};

44
src/config/stream.rs Normal file
View File

@@ -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<S: Into<String>>(line: S, source: StreamSource) -> Self {
Self {
line: line.into(),
source,
}
}
pub fn stdout<S: Into<String>>(line: S) -> Self {
Self {
line: line.into(),
source: StreamSource::Stdout,
}
}
pub fn stderr<S: Into<String>>(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)
}
}

View File

@@ -5,11 +5,13 @@ use std::{
use crate::error::VersionError; use crate::error::VersionError;
/// Identifies the type of Minecraft distribution supported by the configuration.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub enum MinecraftType { pub enum MinecraftType {
Vanilla, Vanilla,
} }
/// Semantic release version parsed from strings like `1.20.4`.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct Version { pub struct Version {
pub major: u32, pub major: u32,
@@ -17,6 +19,7 @@ pub struct Version {
pub patch: u32, pub patch: u32,
} }
/// Snapshot version parsed from strings like `23w13b`.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct Snapshot { pub struct Snapshot {
pub year: u32, pub year: u32,
@@ -24,24 +27,13 @@ pub struct Snapshot {
pub build: char, pub build: char,
} }
/// Enum covering both release and snapshot Minecraft version formats.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub enum MinecraftVersion { pub enum MinecraftVersion {
Release(Version), Release(Version),
Snapshot(Snapshot), 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 { impl Display for Version {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}.{}.{}", self.major, self.minor, self.patch) write!(f, "{}.{}.{}", self.major, self.minor, self.patch)
@@ -136,32 +128,3 @@ impl FromStr for MinecraftVersion {
Err(VersionError::UnknownVersionFormat(s.to_string())) Err(VersionError::UnknownVersionFormat(s.to_string()))
} }
} }
impl StreamLine {
pub fn new<S: Into<String>>(line: S, source: StreamSource) -> Self {
Self {
line: line.into(),
source,
}
}
pub fn stdout<S: Into<String>>(line: S) -> Self {
Self {
line: line.into(),
source: StreamSource::Stdout,
}
}
pub fn stderr<S: Into<String>>(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)
}
}