Function parse

Source
pub fn parse(data: &[u8]) -> Result<String, ParserError>
Expand description

Parses the given data into plain text.

This function is the main entry point for the parser library. It automatically detects the file type from the provided byte data and delegates the parsing to the appropriate specialized parser.

§Arguments

  • data - A byte slice containing the file data to be parsed

§Returns

  • Ok(String) - The extracted text content from the file
  • Err(ParserError) - If the file type is unsupported, unrecognized, or an error occurs during parsing

§Examples

// Attempt to parse the data
match parse(&data) {
    Ok(text) => println!("Parsed text: {}", text),
    Err(err) => println!("Failed to parse: {}", err),
}

§Text file example

use parser_core::parse;

// Create a simple text file content
let text_data = b"Hello, world! This is a sample text file.";

// Parse the text data
let result = parse(text_data).expect("Failed to parse text data");

// Verify the result
assert_eq!(result, "Hello, world! This is a sample text file.");