From d25785984dad2565c1f02b6e5b7e353799f5dade Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 27 Feb 2024 08:48:32 +0100 Subject: [PATCH] add docs for Law::from_config() --- src/law/mod.rs | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/src/law/mod.rs b/src/law/mod.rs index 9d3dbab..33d3126 100644 --- a/src/law/mod.rs +++ b/src/law/mod.rs @@ -19,6 +19,7 @@ use serde::{Deserialize, Serialize}; use std::{ cell::RefCell, fmt::{self, Display}, + path::Path, rc::Rc, sync::Arc, }; @@ -35,12 +36,46 @@ pub struct Law { } impl Law { - pub fn from_config(path: &str) -> Result { + /// Creates a `Law` instance from a configuration file. + /// + /// This function initializes the law processing pipeline by loading configurations from the + /// specified path, parsing law texts based on these configurations, and assembling a `Law` + /// object. The configuration file is expected to define how law texts should be parsed and + /// processed. + /// + /// # Parameters + /// + /// - `path`: A path to the configuration file. This can be any type that implements the + /// `AsRef` trait, allowing for flexible path specifications (e.g., `&str`, `String`, + /// `Path`, or `PathBuf`). + /// + /// # Returns + /// + /// Returns a `Result` that, on success, contains the `Law` constructed from the provided + /// configuration and parsed law texts. On failure, it returns an `Error` indicating what went + /// wrong during the process. + /// + /// # Errors + /// + /// This function can return an `Error` in the following scenarios: + /// + /// - If loading the configuration from the specified path fails (e.g., file not found, + /// permission issues, or invalid file format). - If the parsing of law texts encounters an + /// error or if the construction of the `Law` object based on the parsed data fails. + /// + /// # Examples + /// + /// ``` + /// use risp::law::Law; + /// + /// let law = Law::from_config("./data/configs/abgb.toml").unwrap(); + /// ``` + pub fn from_config>(path: P) -> Result { let (law_id, mut builder, parser) = Config::load(path)?; - let pars = parse(law_id).unwrap(); + let pars = parse(law_id)?; for par in pars { - let cont = parser.parse(&par, &mut builder).unwrap(); + let cont = parser.parse(&par, &mut builder)?; if !cont { break; }