MCPcopy Create free account
hub / github.com/archlinux/alpm / from_string

Method from_string

alpm-srcinfo/src/source_info/v1/mod.rs:172–185  ·  view source on GitHub ↗

Parses a SRCINFO file's content into a [`SourceInfoV1`] struct. # Error This function returns two types of errors. 1. An [`Error`] is returned if the input is, for example, invalid UTF-8 or if the input SRCINFO file couldn't be parsed due to invalid syntax. 2. An [`Error`] is returned if the parsed data is incomplete or otherwise invalid. ```rust use alpm_srcinfo::SourceInfoV1; use alpm_types::

(content: &str)

Source from the content-addressed store, hash-verified

170 /// # }
171 /// ```
172 pub fn from_string(content: &str) -> Result<SourceInfoV1, Error> {
173 // A temporary fix for <https://github.com/winnow-rs/winnow/issues/847>
174 let content_no_tabs = content.replace('\t', " ");
175
176 // Parse the given srcinfo content.
177 let parsed = SourceInfoContent::parser
178 .parse(content_no_tabs.as_str())
179 .map_err(|err| Error::ParseError(format!("{err}")))?;
180
181 // Bring it into a proper structural representation
182 let source_info = SourceInfoV1::from_raw(parsed)?;
183
184 Ok(source_info)
185 }
186
187 /// Reads raw [`SourceInfoContent`] from a first parsing step and converts it into a
188 /// [`SourceInfoV1`].

Callers

nothing calls this directly

Calls 2

parseMethod · 0.80
as_strMethod · 0.45

Tested by

no test coverage detected