handle Code::multiline_continue_from result

This commit is contained in:
yggverse 2024-12-02 15:12:26 +02:00
parent 7f6c459065
commit 8c00d4bf89
6 changed files with 50 additions and 8 deletions

16
src/line/code/error.rs Normal file
View file

@ -0,0 +1,16 @@
use std::fmt::{Display, Formatter, Result};
#[derive(Debug)]
pub enum Error {
Multiline(crate::line::code::multiline::Error),
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> Result {
match self {
Self::Multiline(e) => {
write!(f, "Multiline error: {e}")
}
}
}
}

View file

@ -1,3 +1,6 @@
pub mod error;
pub use error::Error;
use glib::GString;
pub struct Multiline {
@ -28,10 +31,10 @@ impl Multiline {
/// Continue preformatted buffer from line,
/// set `completed` as True on close tag found
pub fn continue_from(&mut self, line: &str) {
pub fn continue_from(&mut self, line: &str) -> Result<(), Error> {
// Make sure buffer not completed yet
if self.completed {
panic!("Could not continue as completed") // @TODO handle
return Err(Error::Completed);
}
// Line contain close tag
@ -42,5 +45,7 @@ impl Multiline {
// Append data to the buffer, trim close tag on exists
self.buffer
.push(GString::from(line.trim_end_matches("```")));
Ok(())
}
}

View file

@ -0,0 +1,16 @@
use std::fmt::{Display, Formatter, Result};
#[derive(Debug)]
pub enum Error {
Completed,
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> Result {
match self {
Self::Completed => {
write!(f, "Could not continue as completed!")
}
}
}
}