source_text/parsable.rs
1use crate::LoadSource;
2
3/// A type that can be parsed from a text `&str`; this provides a `parse_source` default method for
4/// parsing any `LoadSource` value such as `&str` or `&Path`:
5pub trait Parsable: Sized {
6 /// Parse this type from a text `&str`.
7 fn parse_text(text: &str) -> anyhow::Result<Self>;
8
9 /// Parse this type from any [LoadSource] input.
10 ///
11 /// The default implementation loads the source and delegates to [Parsable::parse_text].
12 fn parse_source<S>(source: S) -> anyhow::Result<Self>
13 where
14 S: LoadSource,
15 {
16 crate::process_text(source, Self::parse_text)
17 }
18}