Function parse

Source
pub fn parse(
    bible_reference: &str,
) -> Result<BibleReferenceRepresentation, Box<dyn Error>>
Expand description

Parses a given bible reference with all supported languages and returns an Result<BibleReference, Box<dyn Error>> depending on whether the parsing was successful.

§Params

  • bible_reference: the given bible reference as a string

§Returns

A Result<BibleReferenceRepresentation> with the following possible outcomes:

§Example

// Exodus 3 exists and is a valid Bible reference (of type BibleChapter)
assert!(parse("Exodus 3").is_ok());
// The same applies with John 3,16
assert!(parse("John 3,16").is_ok());
// Revelation 24 does not exist and (as the book only has 21 chapters) and therefore not a valid Bible reference
assert!(parse("Revelation 24").is_err());
// You can display the error message as a string (in English)
assert!(parse("Revelation 24").err().unwrap().to_string().contains("The chapter does not exist"));
// An empty string is not a valid Bible reference
assert!(parse("").err().unwrap().downcast_ref::<ReferenceIsEmptyError>().is_some());