pub trait ChatParser: Send + Sync {
// Required methods
fn name(&self) -> &'static str;
fn parse(
&self,
file_path: &str,
) -> Result<Vec<InternalMessage>, Box<dyn Error>>;
}Expand description
Trait for parsing chat exports from different messengers.
Implement this trait to add support for a new chat source.
The parser should convert the source-specific format into
a vector of InternalMessage structs.
§Example Implementation
use chatpack::parsers::ChatParser;
use chatpack::core::InternalMessage;
use std::error::Error;
struct DiscordParser;
impl ChatParser for DiscordParser {
fn name(&self) -> &'static str {
"Discord"
}
fn parse(&self, file_path: &str) -> Result<Vec<InternalMessage>, Box<dyn Error>> {
let content = std::fs::read_to_string(file_path)?;
// Parse Discord-specific format...
Ok(vec![])
}
}Required Methods§
Sourcefn name(&self) -> &'static str
fn name(&self) -> &'static str
Returns the human-readable name of the chat source.
Used for logging and error messages.
Sourcefn parse(&self, file_path: &str) -> Result<Vec<InternalMessage>, Box<dyn Error>>
fn parse(&self, file_path: &str) -> Result<Vec<InternalMessage>, Box<dyn Error>>
Parses a chat export file and returns a list of messages.
§Arguments
file_path- Path to the export file
§Returns
Ok(Vec<InternalMessage>)- Parsed messages in chronological orderErr- If parsing fails (file not found, invalid format, etc.)
§Notes
- Messages should be returned in chronological order (oldest first)
- Empty or whitespace-only messages may be filtered out
- Platform-specific metadata should be preserved where available