irongit

A rust macro that allows regular expression creation through independent files. Allows fully typed named groups.

added docstrings

huncholanehuncholaneauthored
parent a7afa48commit 65bbb42c8b88b33c91095847fc1703be3c91156aBrowse files

1 file changed, +8 -0

+8-0src/lib.rs
@@ -111,6 +111,8 @@ pub fn load_regex_files(input: TokenStream) -> TokenStream {
111111 }
112112
113113 impl #ident {
114+ /// Extracts the first regex match for the given string
115+ /// This match contains `start_pos`, `end_pos`, and `val`
114116 pub fn from_str(text: &str) -> Option<Self> {
115117 let re = &RE.#ident;
116118 let captures = re.captures(text);
@@ -125,11 +127,15 @@ pub fn load_regex_files(input: TokenStream) -> TokenStream {
125127 }
126128 }
127129
130+ /// Extracts the first regex match for the text content of the given filename
131+ /// This match contains `start_pos`, `end_pos`, and `val`
128132 pub fn from_file(filename: &str) -> Result<Option<Self>, std::io::Error> {
129133 let text = std::fs::read_to_string(filename)?;
130134 Ok(Self::from_str(&text))
131135 }
132136
137+ /// Extracts all regex matches for the given string
138+ /// Each match contains a `start_pos`, `end_pos`, and each field for the given class contains `start_pos`, `end_pos`, and `val`
133139 pub fn vec_from_str(text: &str) -> Vec<Self> {
134140 let re = &RE.#ident;
135141 re.captures_iter(text)
@@ -143,6 +149,8 @@ pub fn load_regex_files(input: TokenStream) -> TokenStream {
143149 .collect()
144150 }
145151
152+ /// Extracts all regex matches for the text contents of a given file
153+ /// Each match contains a `start_pos`, `end_pos`, and each field for the given class contains `start_pos`, `end_pos`, and `val`
146154 pub fn vec_from_file(filename: &str) -> Result<Vec<Self>, std::io::Error> {
147155 let text = std::fs::read_to_string(filename)?;
148156 Ok(Self::vec_from_str(&text))