Function solp::parse_file
source · pub fn parse_file(path: &str, consumer: &mut dyn Consume) -> Result<()>
Expand description
Parses a solution file at the specified path and notifies the consumer of the result.
This function reads the content of the file at the given path and attempts to parse it
as a Microsoft Visual Studio solution file. If the file is successfully read and parsed,
the consumer’s ok
method is called with the parsed Solution
. If any errors occur during
reading or parsing, the consumer’s err
method is called with the path of the file, and an
error is returned.
§Parameters
path
: A string slice that holds the path to the solution file.consumer
: A mutable reference to an object that implements theConsume
trait. This consumer will be notified of the result of the parse operation.
§Returns
A Result
which is Ok(())
if the file was successfully read and parsed, or an error if any
issues occurred during reading or parsing.
§Errors
This function will return an error if the file cannot be read or if the content cannot be parsed
as a valid solution file. In both cases, the consumer’s err
method will be called with the path
of the file.
§Example
use solp::parse_file;
use solp::api::Solution;
use solp::Consume;
struct Consumer;
impl Consume for Consumer {
fn ok(&mut self, solution: &Solution) {
// ...
}
fn err(&self, path: &str) {
// ...
}
}
let path = "path/to/solution.sln";
let mut consumer = Consumer{};
match parse_file(path, &mut consumer) {
Ok(()) => println!("Successfully parsed the solution file."),
Err(e) => eprintln!("Failed to parse the solution file: {:?}", e),
}