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>)
| 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 | |
| 229 | impl FromStr for SourceInfo { |
nothing calls this directly
no outgoing calls
no test coverage detected