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

Method from_str_with_schema

alpm-srcinfo/src/source_info/mod.rs:212–226  ·  view source on GitHub ↗

Creates a [`SourceInfo`] from string slice, optionally validated using a [`SourceInfoSchema`]. If `schema` is [`None`] attempts to detect the [`SourceInfoSchema`] from `s`. Attempts to create a [`SourceInfo`] variant that corresponds to the [`SourceInfoSchema`]. # Note To automatically derive the [`SourceInfoSchema`], use [`SourceInfo::from_str`]. # Examples ``` use std::{fs::File, io::Write}

(s: &str, schema: Option<SourceInfoSchema>)

Source from the content-addressed store, hash-verified

210 /// - a [`SourceInfoSchema`] cannot be derived from `s`,
211 /// - or the detected variant of [`SourceInfo`] cannot be constructed from `s`.
212 fn from_str_with_schema(s: &str, schema: Option<SourceInfoSchema>) -> Result<Self, Error> {
213 // NOTE: This does not use `SourceInfoSchema::derive_from_str`,
214 // to not run the parser twice.
215 // In the future, this should run `SourceInfoContent` parser directly
216 // and delegate to `from_raw` instead of `from_string`.
217
218 let schema = match schema {
219 Some(schema) => schema,
220 None => SourceInfoSchema::V1(SchemaVersion::new(Version::new(1, 0, 0))),
221 };
222
223 match schema {
224 SourceInfoSchema::V1(_) => Ok(SourceInfo::V1(SourceInfoV1::from_string(s)?)),
225 }
226 }
227}
228
229impl FromStr for SourceInfo {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected