summaryrefslogtreecommitdiffstats
path: root/src/log
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-11-04 14:58:11 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-11-04 16:43:27 +0100
commitef17fc10480e1bedf78dcf65076a354aeaef17ec (patch)
tree96e4acc23de733c0224e7f812c755b682daf7dba /src/log
parentd74f753cf638b481fd85da8f5aae7227ff65ab8e (diff)
Move LogItem type to own module
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/log')
-rw-r--r--src/log/item.rs35
-rw-r--r--src/log/mod.rs3
-rw-r--r--src/log/parser.rs17
3 files changed, 39 insertions, 16 deletions
diff --git a/src/log/item.rs b/src/log/item.rs
new file mode 100644
index 0000000..1e5d62a
--- /dev/null
+++ b/src/log/item.rs
@@ -0,0 +1,35 @@
+use std::convert::TryInto;
+
+use anyhow::Result;
+use anyhow::Error;
+
+#[derive(Debug, PartialEq, Eq, Hash)]
+pub enum LogItem {
+ /// A line from the log, unmodified
+ Line(Vec<u8>),
+
+ /// A progress report
+ Progress(usize),
+
+ /// The name of the current phase the process is in
+ CurrentPhase(String),
+
+ /// The end-state of the process
+ /// Either Ok or Error
+ State(Result<String, String>),
+}
+
+impl TryInto<String> for LogItem {
+ type Error = anyhow::Error;
+
+ fn try_into(self) -> Result<String> {
+ match self {
+ LogItem::Line(v) => String::from_utf8(v).map_err(Error::from),
+ LogItem::Progress(u) => Ok(format!("#BUTIDO:PROGRESS:{}", u)),
+ LogItem::CurrentPhase(p) => Ok(format!("#BUTIDO:PHASE:{}", p)),
+ LogItem::State(Ok(s)) => Ok(format!("#BUTIDO:STATE:OK:{}", s)),
+ LogItem::State(Err(s)) => Ok(format!("#BUTIDO:STATE:ERR:{}", s)),
+ }
+ }
+}
+
diff --git a/src/log/mod.rs b/src/log/mod.rs
index d73ab0a..24042ed 100644
--- a/src/log/mod.rs
+++ b/src/log/mod.rs
@@ -1,5 +1,8 @@
mod parser;
pub use parser::*;
+mod item;
+pub use item::*;
+
mod util;
diff --git a/src/log/parser.rs b/src/log/parser.rs
index 18016a2..9a604be 100644
--- a/src/log/parser.rs
+++ b/src/log/parser.rs
@@ -14,6 +14,7 @@ use pom::parser::Parser as PomParser;
use shiplift::tty::TtyChunk;
use crate::log::util::*;
+use crate::log::LogItem;
type IoResult<T> = RResult<T, futures::io::Error>;
@@ -26,22 +27,6 @@ pub fn buffer_stream_to_line_stream<S>(stream: S) -> impl Stream<Item = IoResult
.lines()
}
-#[derive(Debug, PartialEq, Eq, Hash)]
-pub enum LogItem {
- /// A line from the log, unmodified
- Line(Vec<u8>),
-
- /// A progress report
- Progress(usize),
-
- /// The name of the current phase the process is in
- CurrentPhase(String),
-
- /// The end-state of the process
- /// Either Ok or Error
- State(Result<String, String>),
-}
-
pub fn parser<'a>() -> PomParser<'a, u8, LogItem> {
use pom::parser::*;
use pom::char_class::hex_digit;