### Basic Manifest Example Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/index.html A simple manifest file structure. ```TOML [package] name = "my-package" version = "1.0.0" edition = "2021" [dependencies] serde = "1.0.0" tokio = { version = "1.0.0", features = ["full"] } ``` -------------------------------- ### Dependency Format Examples Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/index.html Examples of various dependency declaration formats supported by the parser. ```TOML [dependencies] simple = "1.0.0" complex = { version = "1.0.0", features = ["async"] } local = { path = "../local-dep" } git-dep = { git = "https://github.com/user/repo" } ``` -------------------------------- ### Complex Manifest Example Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/index.html A more complex manifest file including git dependencies, binary definitions, and features. ```TOML [package] name = "complex-package" version = "0.1.0-alpha+build.123" edition = "2021" [dependencies] local-dep = { path = "../local" } git-dep = { git = "https://github.com/user/repo" } [[bin]] name = "tool" path = "src/main.rs" [features] default = ["async"] async = ["tokio"] ``` -------------------------------- ### Define Whitespace and Comment Rules Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/index.html Rules for handling basic formatting, including whitespace characters and line comments starting with #. ```Pest WHITESPACE = _{ " " | "\t" | "\r" | "\n" } COMMENT = _{ "#" ~ (!NEWLINE ~ ANY)* ~ (NEWLINE | EOI) } ``` -------------------------------- ### Get Manifest Sections Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/struct.Manifest.html Retrieves an iterator over the section names in the manifest. Each section name is returned as a string slice. ```rust pub fn sections(&self) -> impl Iterator ``` -------------------------------- ### Define Main Manifest Rule Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/index.html The top-level grammar rule that defines the complete manifest structure from start to end of input. ```Pest manifest = { SOI ~ package_section ~ (section | dependencies_section)* ~ EOI } ``` -------------------------------- ### Get Value by Key Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/struct.Manifest.html Retrieves a value from the manifest given a section and key. Requires the section name and the key. Returns a Result containing either the value as a string slice or a ManifestError. ```rust pub fn get_by_key( &self, section: &str, key: &str, ) -> Result<&str, ManifestError> ``` -------------------------------- ### Get Section by Name Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/struct.Manifest.html Retrieves a section from the manifest as a map of key-value pairs. Requires the section name. Returns a Result containing either the section map or a ManifestError. ```rust pub fn get_by_section( &self, section: &str, ) -> Result<&HashMap, ManifestError> ``` -------------------------------- ### Define WHITESPACE and COMMENT rules Source: https://docs.rs/manifest_parser_rs/0.2.0/index.html These Pest grammar rules define how whitespace and comments are handled. WHITESPACE matches spaces, tabs, returns, and newlines. COMMENT matches lines starting with '#' until a newline or end of input. ```pest WHITESPACE = _{" " | "\t" | "\r" | "\n"} COMMENT = _{ "#" ~ (!NEWLINE ~ ANY)* ~ (NEWLINE | EOI) } ``` -------------------------------- ### Define WHITESPACE and COMMENT rules Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs These Pest grammar rules define how whitespace and comments are handled. WHITESPACE matches standard whitespace characters, and COMMENT matches lines starting with '#' until a newline or end of input. ```pest WHITESPACE = _{" " | "\t" | "\r" | "\n"} COMMENT = _{"#" ~ (!NEWLINE ~ ANY)* ~ (NEWLINE | EOI)} ``` -------------------------------- ### Define Versioning Rules Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/index.html Grammar rules for parsing SemVer strings, including support for pre-release and build metadata. ```Pest version_core = _{ numeric_identifier ~ "." ~ numeric_identifier ~ "." ~ numeric_identifier } version = { "\"" ~ version_core ~ ("-" ~ pre_release)? ~ ("+" ~ build)? ~ "\"" } ``` -------------------------------- ### Define dependency specification formats Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs This Pest grammar rule outlines the various formats for specifying dependencies, including version, git, path, registry, workspace, optional dependencies, and features. ```pest dependency_spec = { "{" ~ ( dependency_version | dependency_git | dependency_path | dependency_registry | dependency_workspace | dependency_optional | features )+ ~ "}" } ``` -------------------------------- ### CloneToUninit Trait (Nightly Only) Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Provides experimental methods for cloning to uninitialized memory. ```APIDOC ## UNSAFE POST /clone_to_uninit ### Description Performs copy-assignment from `self` to `dest`. ### Method POST ### Endpoint /clone_to_uninit ### Parameters #### Request Body - **self** (T) - Required - The value to copy. - **dest** (*mut u8) - Required - A mutable pointer to the destination memory. ### Request Example ```json { "self": "value", "dest": "pointer" } ``` ### Response #### Success Response (200) This method does not return a value upon success. ### Response Example ```json { "example": "Success" } ``` ``` -------------------------------- ### Define Package Section Structure Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/index.html Grammar rule for the mandatory package section containing name, version, and metadata. ```Pest package_section = { "[package]" ~ "name" ~ "=" ~ value ~ "version" ~ "=" ~ version ~ section_inside } ``` -------------------------------- ### ManifestParser::parse Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/struct.ManifestParser.html Parses a string input based on a specified rule. ```APIDOC ## fn parse<'i>(rule: Rule, input: &'i str) -> Result, Error> ### Description Parses a `&str` starting from a specific `Rule`. ### Parameters - **rule** (Rule) - Required - The rule to start parsing from. - **input** (&str) - Required - The input string to be parsed. ### Response - **Result, Error>** - Returns a collection of parsed pairs on success, or an error if parsing fails. ``` -------------------------------- ### Define Dependencies Section Structure Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/index.html Grammar rules for parsing dependency sections and individual dependency specifications. ```Pest dependencies_section = { ("[dependencies]" | "[dev-dependencies]") ~ dependencies_key_value* } dependency_spec = { "{" ~ ( dependency_version | dependency_git | dependency_path | dependency_registry | dependency_workspace | dependency_optional | features )+ ~ "}" } ``` -------------------------------- ### Manifest Parsing and Retrieval Source: https://docs.rs/manifest_parser_rs/0.2.0/src/manifest_parser_rs/lib.rs.html Methods for parsing raw manifest strings and retrieving data by section or key. ```APIDOC ## POST /manifest/parse ### Description Parses a raw manifest string into a structured Manifest object. ### Method POST ### Endpoint /manifest/parse ### Request Body - **input** (string) - Required - The raw manifest content string. ### Response #### Success Response (200) - **manifest** (object) - The parsed manifest structure containing sections and key-value pairs. --- ## GET /manifest/sections/{section}/{key} ### Description Retrieves a specific value from the manifest based on the section and key provided. ### Method GET ### Endpoint /manifest/sections/{section}/{key} ### Parameters #### Path Parameters - **section** (string) - Required - The name of the section. - **key** (string) - Required - The key within the section. ### Response #### Success Response (200) - **value** (string) - The value associated with the specified key. --- ## GET /manifest/sections/{section} ### Description Retrieves an entire section from the manifest as a map of key-value pairs. ### Method GET ### Endpoint /manifest/sections/{section} ### Parameters #### Path Parameters - **section** (string) - Required - The name of the section to retrieve. ### Response #### Success Response (200) - **section_map** (object) - A map of key-value pairs representing the requested section. ``` -------------------------------- ### Define Key-Value Pair Rules Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/index.html Grammar rules for parsing generic key-value pairs. ```Pest key = @{ (ASCII_ALPHANUMERIC | "_" | "-")+ value = @{ (!NEWLINE ~ WHITESPACE* ~ possible_value_char)+ key_value = { key ~ "=" ~ value } ``` -------------------------------- ### Define Section Names Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/index.html Predefined list of valid section names allowed within the manifest structure. ```Pest section_name = @{ "lib" | "bin" | "example" | "test" | "bench" | "build-dependencies" | "target" | "badges" | "features" | "lints" | "patch" | "replace" | "profile" | "workspace" } ``` -------------------------------- ### Implement Manifest Data Structure and Parsing Logic Source: https://docs.rs/manifest_parser_rs/0.2.0/src/manifest_parser_rs/lib.rs.html The Manifest struct stores parsed data in a HashMap and provides methods for parsing input strings and retrieving values by section or key. ```rust 35/// Represents a parsed manifest containing sections of key-value pairs. 36#[derive(Debug, Default)] 37pub struct Manifest { 38 /// Map of section names to their key-value pairs 39 sections: HashMap>, 40} 41 42impl Manifest { 43 /// Parses a manifest string into a structured format. 44 /// 45 /// # Arguments 46 /// 47 /// * `input` - The manifest content as a string 48 /// 49 /// # Returns 50 /// 51 /// A `Result` containing either a parsed `Manifest` or a `ManifestError` 52 pub fn parse(input: &str) -> Result { 53 let mut manifest = Manifest::default(); 54 let parsed_item = ManifestParser::parse(Rule::manifest, input) 55 .map_err(|e| ManifestError::ParseError(e.to_string()))?; 56 let mut current_section = None; 57 58 for item in parsed_item.flatten() { 59 match item.as_rule() { 60 Rule::section => { 61 current_section = parse_section(item); 62 manifest 63 .sections 64 .insert(current_section.clone().unwrap(), HashMap::new()); 65 } 66 Rule::key_value => { 67 parse_key_value(item, &mut manifest, ¤t_section)?; 68 } 69 Rule::package_section => { 70 parse_package_section(item, &mut manifest)?; 71 } 72 Rule::dependencies_section => { 73 parse_dependencies_section(item, &mut manifest)?; 74 } 75 _ => {} 76 } 77 } 78 79 Ok(manifest) 80 } 81 82 /// Retrieves an iterator over the section names in the manifest. 83 /// 84 /// # Returns 85 /// 86 /// An iterator yielding references to the section names as strings. 87 pub fn sections(&self) -> impl Iterator { 88 self.sections.keys() 89 } 90 91 /// Retrieves a value from the manifest given a section and key. 92 /// 93 /// # Arguments 94 /// 95 /// * `section` - The section name 96 /// * `key` - The key within the section 97 /// 98 /// # Returns 99 /// 100 /// A `Result` containing either the value as a string slice or a `ManifestError` 101 pub fn get_by_key(&self, section: &str, key: &str) -> Result<&str, ManifestError> { 102 let section_map = self 103 .sections 104 .get(section) 105 .ok_or_else(|| ManifestError::MissingSection(section.to_string()))?; 106 107 let value = section_map 108 .get(key) 109 .ok_or_else(|| ManifestError::MissingKey(section.to_string(), key.to_string()))?; 110 111 Ok(value) 112 } 113 114 /// Retrieves a section from the manifest as a map of key-value pairs. 115 /// 116 /// # Arguments 117 /// 118 /// * `section` - The section name 119 /// 120 /// # Returns 121 /// 122 /// A `Result` containing either the section map or a `ManifestError` 123 pub fn get_by_section(&self, section: &str) -> Result<&HashMap, ManifestError> { 124 let section_map = self 125 .sections 126 .get(section) 127 .ok_or_else(|| ManifestError::MissingSection(section.to_string()))?; 128 129 Ok(section_map) 130 } 131} ``` -------------------------------- ### Parse package section in Rust Source: https://docs.rs/manifest_parser_rs/0.2.0/src/manifest_parser_rs/lib.rs.html Parses the package section, extracting name and version metadata along with additional key-value pairs. ```rust fn parse_package_section( item: pest::iterators::Pair, manifest: &mut Manifest, ) -> Result<(), ManifestError> { let section_name = "package".to_string(); manifest .sections .insert(section_name.clone(), HashMap::new()); let mut inner = item.into_inner(); let name = inner.next().unwrap().as_str().trim(); let version = inner.next().unwrap().as_str().trim(); let section_map = manifest.sections.get_mut(§ion_name).unwrap(); section_map.insert("name".to_string(), name.trim_matches('"').to_string()); section_map.insert("version".to_string(), version.trim_matches('"').to_string()); //Check if there are items left let inner = inner.next().unwrap().into_inner(); for item in inner { let mut inner = item.into_inner(); let key = inner.next().unwrap().as_str().trim(); let value = inner.next().unwrap().as_str().trim().trim_matches('"'); section_map.insert(key.to_string(), value.to_string()); } Ok(()) } ``` -------------------------------- ### Define version parsing rules Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs These Pest grammar rules define the structure for parsing semantic versioning strings. version_core handles the MAJOR.MINOR.PATCH format, while version includes optional pre-release and build metadata, enclosed in quotes. ```pest version_core = _{"numeric_identifier" ~ "." ~ "numeric_identifier" ~ "." ~ "numeric_identifier"} version = {"\"" ~ version_core ~ ("-" ~ pre_release)? ~ ("+" ~ build)? ~ "\""} ``` -------------------------------- ### Rule Implementations Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html This section details the implementations of the Rule enum, including methods for parsing and trait implementations for common operations. ```APIDOC ## Implementations ### impl Rule #### pub fn all_rules() -> &'static [Rule] Returns a static slice of all defined `Rule` variants. ### impl Clone for Rule #### fn clone(&self) -> Rule Returns a duplicate of the value. #### fn clone_from(&mut self, source: &Self) Performs copy-assignment from `source`. ### impl Debug for Rule #### fn fmt(&self, f: &mut Formatter<'_>) -> Result Formats the value using the given formatter. ### impl Hash for Rule #### fn hash<__H: Hasher>(&self, state: &mut __H) Feeds this value into the given `Hasher`. #### fn hash_slice(data: &[Self], state: &mut H) where H: Hasher, Self: Sized, Feeds a slice of this type into the given `Hasher`. ### impl Ord for Rule #### fn cmp(&self, other: &Rule) -> Ordering This method returns an `Ordering` between `self` and `other`. #### fn max(self, other: Self) -> Self where Self: Sized, Compares and returns the maximum of two values. #### fn min(self, other: Self) -> Self where Self: Sized, Compares and returns the minimum of two values. #### fn clamp(self, min: Self, max: Self) -> Self where Self: Sized, Restrict a value to a certain interval. ### impl Parser for ManifestParser #### fn parse<'i>(rule: Rule, input: &'i str) -> Result, Error> Parses a `&str` starting from `rule`. ### impl PartialEq for Rule #### fn eq(&self, other: &Rule) -> bool Tests for `self` and `other` values to be equal. #### fn ne(&self, other: &Rhs) -> bool Tests for `!=`. ### impl PartialOrd for Rule #### fn partial_cmp(&self, other: &Rule) -> Option This method returns an ordering between `self` and `other` values if one exists. #### fn lt(&self, other: &Rhs) -> bool Tests less than (for `self` and `other`) and is used by the `<` operator. #### fn le(&self, other: &Rhs) -> bool Tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. #### fn gt(&self, other: &Rhs) -> bool Tests greater than (for `self` and `other`) and is used by the `>` operator. #### fn ge(&self, other: &Rhs) -> bool Tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. ### impl Copy for Rule ### impl Eq for Rule ### impl StructuralPartialEq for Rule ``` -------------------------------- ### Define General Section Structure Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/index.html Grammar rules for defining sections, supporting both single and double bracket syntax. ```Pest section_definition = { "[" ~ "["? ~ section_name ~ "]" ~ "]"? } section_inside = { key_value* } section = { section_definition ~ section_inside } ``` -------------------------------- ### Blanket Implementations for Rule Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Shows blanket implementations for generic traits applied to the Rule enum. ```APIDOC ## Blanket Implementations ### impl Any for T where T: 'static + ?Sized, #### fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. ### impl Borrow for T where T: ?Sized, ``` -------------------------------- ### Rule::all_rules Implementation Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Returns a static slice containing all defined Rule variants. Useful for iterating over all possible parsing rules. ```rust pub fn all_rules() -> &'static [Rule] ``` -------------------------------- ### Manifest Parsing API Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/struct.Manifest.html Provides functionality to parse manifest strings into a structured Manifest object. ```APIDOC ## POST /manifest/parse ### Description Parses a manifest string into a structured format. ### Method POST ### Endpoint /manifest/parse ### Parameters #### Request Body - **input** (string) - Required - The manifest content as a string ### Request Example { "input": "[section]\nkey=value" } ### Response #### Success Response (200) - **Manifest** (object) - A structured Manifest object. - **ManifestError** (object) - An error object if parsing fails. #### Response Example { "sections": ["section"], "data": { "section": { "key": "value" } } } ``` -------------------------------- ### ManifestParser::parse Implementation Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Parses a string slice according to a specified Rule. Returns a Result containing Pairs or an Error. ```rust fn parse<'i>(rule: Rule, input: &'i str) -> Result, Error> ``` -------------------------------- ### Into Trait Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Provides methods for converting a value into another type. ```APIDOC ## POST /into ### Description Calls `U::from(self)`. This conversion is whatever the implementation of `From for U` chooses to do. ### Method POST ### Endpoint /into ### Parameters #### Request Body - **self** (T) - Required - The value to convert. ### Request Example ```json { "self": "value" } ``` ### Response #### Success Response (200) - **U** (U) - The converted value. ### Response Example ```json { "example": "converted_value" } ``` ``` -------------------------------- ### From Trait Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Provides methods for converting a value into itself. ```APIDOC ## POST /from ### Description Returns the argument unchanged. ### Method POST ### Endpoint /from ### Parameters #### Request Body - **t** (T) - Required - The value to convert. ### Request Example ```json { "t": "value" } ``` ### Response #### Success Response (200) - **T** (T) - The unchanged value. ### Response Example ```json { "example": "value" } ``` ``` -------------------------------- ### Define dependencies section structure Source: https://docs.rs/manifest_parser_rs/0.2.0/index.html This Pest grammar rule defines the structure for both [dependencies] and [dev-dependencies] sections, allowing multiple dependency specifications. ```pest dependencies_section = { ("[dependencies]" | "[dev-dependencies]") ~ dependencies_key_value* } ``` -------------------------------- ### Define ManifestParser struct Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/struct.ManifestParser.html The primary structure used for parsing manifest files. ```rust pub struct ManifestParser; ``` -------------------------------- ### Parse Manifest String Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/struct.Manifest.html Parses a manifest string into a structured format. Requires the manifest content as a string. Returns a Result containing either a parsed Manifest or a ManifestError. ```rust pub fn parse(input: &str) -> Result ``` -------------------------------- ### Parse dependencies section in Rust Source: https://docs.rs/manifest_parser_rs/0.2.0/src/manifest_parser_rs/lib.rs.html Parses dependency entries, automatically distinguishing between standard and dev-dependencies. ```rust fn parse_dependencies_section( item: pest::iterators::Pair, manifest: &mut Manifest, ) -> Result<(), ManifestError> { let mut section_name = "dependencies".to_string(); if manifest.sections.contains_key(§ion_name) { section_name = "dev-dependencies".to_string(); } manifest .sections .insert(section_name.clone(), HashMap::new()); for dep in item.into_inner() { let mut inner = dep.into_inner(); let key = inner.next().unwrap().as_str().trim(); let value = inner.next().unwrap().as_str().trim().trim_matches('"'); let section_map = manifest.sections.get_mut(§ion_name).unwrap(); section_map.insert(key.to_string(), value.to_string()); } Ok(()) } ``` -------------------------------- ### Implement Display for ManifestError Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.ManifestError.html Provides a Display implementation for ManifestError, enabling user-friendly string representations of errors. This is useful for logging or user feedback. ```rust fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result ``` -------------------------------- ### Define Manifest Struct Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/struct.Manifest.html Represents a parsed manifest containing sections of key-value pairs. This struct has private fields. ```rust pub struct Manifest { /* private fields */ } ``` -------------------------------- ### Define dependency specification structure Source: https://docs.rs/manifest_parser_rs/0.2.0/index.html This Pest grammar rule outlines the structure for a single dependency specification within the dependencies section, supporting various formats like version, git, path, registry, workspace, optional, and features. ```pest dependency_spec = { "{" ~ ( dependency_version | dependency_git | dependency_path | dependency_registry | dependency_workspace | dependency_optional | features )+ "}" } ``` -------------------------------- ### Define key-value pair rules Source: https://docs.rs/manifest_parser_rs/0.2.0/index.html These Pest grammar rules define the structure for key-value pairs used throughout the manifest. 'key' allows alphanumeric characters, underscores, and hyphens. 'value' accepts any characters except a newline. ```pest key = @{ (ASCII_ALPHANUMERIC | "_" | "-")+} value = @{ (!NEWLINE ~ WHITESPACE* ~ possible_value_char)+ } key_value = { key ~ "=" ~ value } ``` -------------------------------- ### Define key and value parsing rules Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs These Pest grammar rules define the structure for key-value pairs. 'key' allows alphanumeric characters, underscores, and hyphens, while 'value' accepts any characters except a newline. ```pest key = @{ (ASCII_ALPHANUMERIC | "_" | "-")+} value = @{ (!NEWLINE ~ WHITESPACE* ~ possible_value_char)+} key_value = { key ~ "=" ~ value } ``` -------------------------------- ### TryFrom Trait Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Provides methods for attempting to convert a value into another type, returning a Result. ```APIDOC ## POST /try_from ### Description Performs the conversion. Returns a Result indicating success or failure. ### Method POST ### Endpoint /try_from ### Parameters #### Request Body - **value** (U) - Required - The value to attempt to convert. ### Request Example ```json { "value": "value_to_convert" } ``` ### Response #### Success Response (200) - **Result** (Result) - The result of the conversion. #### Response Example ```json { "example": "Ok(converted_value)" } ``` ``` -------------------------------- ### ManifestError Trait Implementations Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.ManifestError.html Provides information on the trait implementations for the ManifestError enum, including Debug, Display, and Error. ```APIDOC ## Trait Implementations for ManifestError ### impl Debug for ManifestError #### fn fmt(&self, f: &mut Formatter<'_>) -> Result Formats the value using the given formatter. ### impl Display for ManifestError #### fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result Formats the value using the given formatter. ### impl Error for ManifestError #### fn source(&self) -> Option<&(dyn Error + 'static)> Returns the lower-level source of this error, if any. #### fn description(&self) -> &str Deprecated since 1.42.0: use the Display impl or to_string(). #### fn cause(&self) -> Option<&dyn Error> Deprecated since 1.33.0: replaced by Error::source, which can support downcasting. #### fn provide<'a>(&'a self, request: &mut Request<'a>) This is a nightly-only experimental API. (`error_generic_member_access`) Provides type-based access to context intended for error reports. ``` -------------------------------- ### Parse key-value pair in Rust Source: https://docs.rs/manifest_parser_rs/0.2.0/src/manifest_parser_rs/lib.rs.html Extracts a key and value from a pest pair and inserts them into the manifest's current section. ```rust fn parse_key_value( item: pest::iterators::Pair, manifest: &mut Manifest, current_section: &Option, ) -> Result<(), ManifestError> { let mut inner = item.into_inner(); let key = inner.next().unwrap().as_str().trim(); let value = inner.next().unwrap().as_str().trim().trim_matches('"'); if let Some(section) = current_section { if let Some(section_map) = manifest.sections.get_mut(section) { section_map.insert(key.to_string(), value.to_string()); } } Ok(()) } ``` -------------------------------- ### Rule::eq Implementation Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Tests for equality between two Rule enum variants. This is part of the PartialEq trait implementation. ```rust fn eq(&self, other: &Rule) -> bool ``` -------------------------------- ### TryInto Trait Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Provides methods for attempting to convert a value into another type, returning a Result. ```APIDOC ## POST /try_into ### Description Performs the conversion. Returns a Result indicating success or failure. ### Method POST ### Endpoint /try_into ### Parameters #### Request Body - **self** (T) - Required - The value to attempt to convert. ### Request Example ```json { "self": "value_to_convert" } ``` ### Response #### Success Response (200) - **Result** (Result>::Error>) - The result of the conversion. #### Response Example ```json { "example": "Ok(converted_value)" } ``` ``` -------------------------------- ### Try Convert Into Another Type Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/struct.Manifest.html Attempts to convert the value into another type. This is part of the TryInto trait implementation. ```rust fn try_into(self) -> Result>::Error> ``` -------------------------------- ### Borrow::borrow Implementation Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Provides a reference to the Rule enum. This is a blanket implementation for the Borrow trait. ```rust impl Borrow for T where T: ?Sized, ``` -------------------------------- ### Manifest Data Retrieval API Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/struct.Manifest.html Allows retrieval of specific data points or entire sections from a parsed Manifest object. ```APIDOC ## GET /manifest/sections ### Description Retrieves an iterator over the section names in the manifest. ### Method GET ### Endpoint /manifest/sections ### Response #### Success Response (200) - **sections** (array[string]) - An array of section names. #### Response Example { "sections": ["section1", "section2"] } ``` ```APIDOC ## GET /manifest/section/{section}/key/{key} ### Description Retrieves a specific value from the manifest given a section and key. ### Method GET ### Endpoint /manifest/section/{section}/key/{key} ### Parameters #### Path Parameters - **section** (string) - Required - The section name - **key** (string) - Required - The key within the section ### Response #### Success Response (200) - **value** (string) - The value associated with the key. #### Response Example { "value": "some_value" } ``` ```APIDOC ## GET /manifest/section/{section} ### Description Retrieves an entire section from the manifest as a map of key-value pairs. ### Method GET ### Endpoint /manifest/section/{section} ### Parameters #### Path Parameters - **section** (string) - Required - The section name ### Response #### Success Response (200) - **section_data** (object) - A map of key-value pairs for the specified section. #### Response Example { "section_data": { "key1": "value1", "key2": "value2" } } ``` -------------------------------- ### Rule::clone_from Implementation Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Performs copy-assignment from a source Rule value to self. This is part of the Clone trait. ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### Auto Trait Implementations for Rule Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Details the auto-derived trait implementations for the Rule enum, indicating thread safety and memory management characteristics. ```APIDOC ## Auto Trait Implementations ### impl Freeze for Rule ### impl RefUnwindSafe for Rule ### impl Send for Rule ### impl Sync for Rule ### impl Unpin for Rule ### impl UnsafeUnpin for Rule ### impl UnwindSafe for Rule ``` -------------------------------- ### Rule::partial_cmp Implementation Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Provides partial ordering comparison between two Rule enum variants. This is part of the PartialOrd trait implementation. ```rust fn partial_cmp(&self, other: &Rule) -> Option ``` -------------------------------- ### Rule::ne Implementation Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Tests for inequality between two Rule enum variants. This is part of the PartialEq trait implementation. ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### Try Convert From Another Type Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/struct.Manifest.html Attempts to convert a value from another type into the current type. This is part of the TryFrom trait implementation. ```rust fn try_from(value: U) -> Result>::Error> ``` -------------------------------- ### Implement ToString for Generic Type T Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.ManifestError.html Implements the ToString trait for any type T that also implements Display. This allows converting values into String format. ```rust fn to_string(&self) -> String ``` -------------------------------- ### Rule::clone Implementation Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Provides the functionality to create a duplicate of a Rule value. This is a standard trait implementation for copyable enums. ```rust fn clone(&self) -> Rule ``` -------------------------------- ### Borrow Trait Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Provides methods for immutable borrowing. ```APIDOC ## GET /borrow ### Description Immutably borrows from an owned value. ### Method GET ### Endpoint /borrow ### Parameters #### Query Parameters - **self** (T) - Required - The owned value to borrow from. ### Response #### Success Response (200) - **&T** (T) - A reference to the borrowed value. ### Response Example ```json { "example": "&T" } ``` ``` -------------------------------- ### Define Manifest Parser and Error Types Source: https://docs.rs/manifest_parser_rs/0.2.0/src/manifest_parser_rs/lib.rs.html The core parser structure uses a Pest grammar file, and the ManifestError enum handles various parsing and validation failures. ```rust 1#![doc = include_str!("../docs.md")] 2//! A parser for manifest files using Pest grammar. 3 4use pest::Parser; 5use pest_derive::Parser; 6use std::collections::HashMap; 7use thiserror::Error; 8 9/// The main parser for manifest files. 10/// This parser reads and validates manifest files that define sections 11/// including package information and dependencies. 12/// 13/// # Example 14/// 15#[derive(Parser)] 16#[grammar = "grammar.pest"] 17pub struct ManifestParser; 18 19/// Represents errors that can occur during manifest parsing. 20#[derive(Debug, Error)] 21pub enum ManifestError { 22 /// Represents a parsing error with details 23 #[error("Parse error: {0}")] 24 ParseError(String), 25 26 /// Indicates a missing section in the manifest 27 #[error("Missing section: {0}")] 28 MissingSection(String), 29 30 /// Indicates a missing key within a section 31 #[error("Missing key {1} in section {0}")] 32 MissingKey(String, String), 33} ``` -------------------------------- ### Implement Debug for ManifestError Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.ManifestError.html Provides a Debug implementation for ManifestError, allowing it to be formatted for debugging purposes. This is automatically derived for most enums. ```rust fn fmt(&self, f: &mut Formatter<'_>) -> Result ``` -------------------------------- ### Define Identifier Rules Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/index.html Rules for parsing identifiers using alphanumeric characters and hyphens. ```Pest non_digit = _{ ASCII_ALPHA | "-" } identifier_characters = _{ (ASCII_DIGIT | non_digit)+ } ``` -------------------------------- ### Implement Any for Generic Type T Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.ManifestError.html Implements the Any trait for any type T, enabling runtime type identification. This is a blanket implementation provided by the standard library. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Default Manifest Value Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/struct.Manifest.html Returns the default value for the Manifest struct, as defined by the Default trait implementation. ```rust fn default() -> Manifest ``` -------------------------------- ### Rule::cmp Implementation Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Compares two Rule enum variants and returns an Ordering. This is part of the Ord trait implementation. ```rust fn cmp(&self, other: &Rule) -> Ordering ``` -------------------------------- ### Implement From for T Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.ManifestError.html Implements the From trait for converting a type T into itself. This is a trivial conversion where the value is returned unchanged. ```rust fn from(t: T) -> T ``` -------------------------------- ### Implement TryInto for Generic Type T Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.ManifestError.html Implements the TryInto trait for attempting to convert type T into type U. This is the reciprocal of TryFrom and also returns a Result for fallible conversions. ```rust type Error = >::Error ``` ```rust fn try_into(self) -> Result>::Error> ``` -------------------------------- ### BorrowMut Trait Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Provides methods for mutable borrowing. ```APIDOC ## GET /borrow_mut ### Description Mutably borrows from an owned value. ### Method GET ### Endpoint /borrow_mut ### Parameters #### Query Parameters - **&mut self** (&mut T) - Required - The owned value to mutably borrow from. ### Response #### Success Response (200) - **&mut T** (&mut T) - A mutable reference to the borrowed value. ### Response Example ```json { "example": "&mut T" } ``` ``` -------------------------------- ### Rule::le Implementation Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Tests if self is less than or equal to other. This is part of the PartialOrd trait implementation. ```rust fn le(&self, other: &Rhs) -> bool ``` -------------------------------- ### Rule::hash Implementation Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Feeds the Rule enum variant into a hasher state. This is part of the Hash trait implementation. ```rust fn hash<__H: Hasher>(&self, state: &mut __H) ``` -------------------------------- ### Implement Into for Generic Type T Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.ManifestError.html Implements the Into trait for converting type T into type U, provided U implements From. This allows for easy type conversions. ```rust fn into(self) -> U ``` -------------------------------- ### Parse Section Names Source: https://docs.rs/manifest_parser_rs/0.2.0/src/manifest_parser_rs/lib.rs.html Helper function to extract and clean section names from Pest pairs, handling optional brackets. ```rust 133/// Parses a section name from the manifest. 134fn parse_section(item: pest::iterators::Pair) -> Option { 135 let inner = item.into_inner().next().unwrap(); 136 let section_name = inner.as_str().trim().to_string(); 137 138 if section_name.starts_with('[') && section_name.ends_with(']') { 139 Some( 140 section_name 141 .trim_matches(|c| c == '[' || c == ']') 142 .to_string(), 143 ) 144 } else { 145 Some(section_name) 146 } 147} ``` -------------------------------- ### Implement TryFrom for Generic Type T Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.ManifestError.html Implements the TryFrom trait for attempting to convert type U into type T. This allows for fallible conversions, returning a Result. ```rust type Error = Infallible ``` ```rust fn try_from(value: U) -> Result>::Error> ``` -------------------------------- ### Enum Rule Definition Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Defines the enumeration for all possible parsing rules used by the manifest_parser_rs. ```rust pub enum Rule { Show 34 variants EOI, WHITESPACE, COMMENT, section_name, non_digit, identifier_characters, numeric_identifier, alphanumeric_identifier, pre_release_identifier, dot_separated_pre_release_identifiers, pre_release, dot_separated_build_identifiers, build, version_core, version, package_section, features, dependency_version, dependency_git, dependency_path, dependency_registry, dependency_workspace, dependency_optional, dependency_spec, dependencies_key_value, dependencies_section, key, value, possible_value_char, key_value, section_definition, section_inside, section, manifest, } ``` -------------------------------- ### Rule::hash_slice Implementation Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Feeds a slice of Rule enum variants into a hasher state. This is part of the Hash trait implementation. ```rust fn hash_slice(data: &[Self], state: &mut H) where H: Hasher, Self: Sized, ``` -------------------------------- ### Rule::min Implementation Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Returns the minimum of two Rule enum variants. This is part of the Ord trait implementation. ```rust fn min(self, other: Self) -> Self where Self: Sized, ``` -------------------------------- ### Rule::ge Implementation Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Tests if self is greater than or equal to other. This is part of the PartialOrd trait implementation. ```rust fn ge(&self, other: &Rhs) -> bool ``` -------------------------------- ### Rule Enum Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html The Rule enum defines various parsing rules used within the manifest_parser_rs crate. It includes variants for different components of a manifest file, such as sections, dependencies, versions, and more. ```APIDOC ## Enum Rule ```rust pub enum Rule { EOI, WHITESPACE, COMMENT, section_name, non_digit, identifier_characters, numeric_identifier, alphanumeric_identifier, pre_release_identifier, dot_separated_pre_release_identifiers, pre_release, dot_separated_build_identifiers, build, version_core, version, package_section, features, dependency_version, dependency_git, dependency_path, dependency_registry, dependency_workspace, dependency_optional, dependency_spec, dependencies_key_value, dependencies_section, key, value, possible_value_char, key_value, section_definition, section_inside, section, manifest, } ``` ### Variants - **EOI**: End-of-input - **WHITESPACE** - **COMMENT** - **section_name** - **non_digit** - **identifier_characters** - **numeric_identifier** - **alphanumeric_identifier** - **pre_release_identifier** - **dot_separated_pre_release_identifiers** - **pre_release** - **dot_separated_build_identifiers** - **build** - **version_core** - **version** - **package_section** - **features** - **dependency_version** - **dependency_git** - **dependency_path** - **dependency_registry** - **dependency_workspace** - **dependency_optional** - **dependency_spec** - **dependencies_key_value** - **dependencies_section** - **key** - **value** - **possible_value_char** - **key_value** - **section_definition** - **section_inside** - **section** - **manifest** ``` -------------------------------- ### Implement BorrowMut for Generic Type T Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.ManifestError.html Implements the BorrowMut trait for any type T, allowing mutable borrowing. This is a standard blanket implementation. ```rust fn borrow_mut(&mut self) -> &mut T ``` -------------------------------- ### Rule::clamp Implementation Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Restricts a Rule enum variant to a specified interval [min, max]. This is part of the Ord trait implementation. ```rust fn clamp(self, min: Self, max: Self) -> Self where Self: Sized, ``` -------------------------------- ### Rule::lt Implementation Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Tests if self is less than other. This is part of the PartialOrd trait implementation. ```rust fn lt(&self, other: &Rhs) -> bool ``` -------------------------------- ### Implement Borrow for Generic Type T Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.ManifestError.html Implements the Borrow trait for any type T, allowing immutable borrowing. This is a standard blanket implementation. ```rust fn borrow(&self) -> &T ``` -------------------------------- ### Rule::gt Implementation Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Tests if self is greater than other. This is part of the PartialOrd trait implementation. ```rust fn gt(&self, other: &Rhs) -> bool ``` -------------------------------- ### Rule::max Implementation Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Returns the maximum of two Rule enum variants. This is part of the Ord trait implementation. ```rust fn max(self, other: Self) -> Self where Self: Sized, ``` -------------------------------- ### ToOwned Trait Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.Rule.html Provides methods for creating owned data from borrowed data. ```APIDOC ## POST /to_owned ### Description Creates owned data from borrowed data, usually by cloning. ### Method POST ### Endpoint /to_owned ### Parameters #### Request Body - **self** (&self) - Required - The borrowed data. ### Request Example ```json { "self": "borrowed_data" } ``` ### Response #### Success Response (200) - **Owned** (T) - The owned data. ### Response Example ```json { "example": "owned_data" } ``` ``` ```APIDOC ## POST /clone_into ### Description Uses borrowed data to replace owned data, usually by cloning. ### Method POST ### Endpoint /clone_into ### Parameters #### Request Body - **self** (&self) - Required - The borrowed data. - **target** (&mut T) - Required - A mutable reference to the owned data to be replaced. ### Request Example ```json { "self": "borrowed_data", "target": "owned_data_reference" } ``` ### Response #### Success Response (200) This method does not return a value upon success. ### Response Example ```json { "example": "Success" } ``` ``` -------------------------------- ### Implement Error Trait for ManifestError Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.ManifestError.html Implements the standard Error trait for ManifestError, allowing it to be used within Rust's error handling mechanisms. This includes methods like `source()` for chained errors. ```rust fn source(&self) -> Option<&(dyn Error + 'static)> ``` ```rust fn description(&self) -> &str ``` ```rust fn cause(&self) -> Option<&dyn Error> ``` ```rust fn provide<'a>(&'a self, request: &mut Request<'a>) ``` -------------------------------- ### Define identifier character rules Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs These Pest grammar rules define the characters allowed in identifiers. non_digit allows alphabetic characters and hyphens, while identifier_characters combines digits and non-digits. ```pest non_digit = _{"ASCII_ALPHA" | "-"} identifier_characters = _{"(" ~ (ASCII_DIGIT | non_digit)+" )"} ``` -------------------------------- ### Define identifier character rules Source: https://docs.rs/manifest_parser_rs/0.2.0/index.html These Pest grammar rules define the characters allowed in identifiers. non_digit allows alphabetic characters and hyphens, while identifier_characters combines digits and non-digits. ```pest non_digit = _{ ASCII_ALPHA | "-" } identifier_characters = _{ (ASCII_DIGIT | non_digit)+ ``` -------------------------------- ### ManifestError Enum Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.ManifestError.html The ManifestError enum represents various errors that can occur during the parsing of manifest files. ```APIDOC ## Enum ManifestError ### Description Represents errors that can occur during manifest parsing. ### Variants #### ParseError(String) Represents a parsing error with details. #### MissingSection(String) Indicates a missing section in the manifest. #### MissingKey(String, String) Indicates a missing key within a section. ``` -------------------------------- ### Define ManifestError Enum Source: https://docs.rs/manifest_parser_rs/0.2.0/manifest_parser_rs/enum.ManifestError.html Defines the ManifestError enum with variants for different parsing issues. Use this enum to handle and report errors during manifest file processing. ```rust pub enum ManifestError { ParseError(String), MissingSection(String), MissingKey(String, String), } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.