rdftk_iri 0.3.2

This crate provides an implementation of the IRI and URI specifications.
Documentation
//!
//! Provides the `Error` type, and the specific `NameParseError` for errors in
//! parsing values to `Name`, `Namespace`, and `LocalName`.
//!

#[cfg(not(feature = "std"))]
use alloc::string::String;

use strum::{EnumIs, EnumTryAs};
use thiserror::Error;
use url::ParseError as UrlError;

///
/// The `Error` type for this crate.
///
#[derive(Debug, Error, EnumIs, EnumTryAs)]
#[allow(missing_docs)] // EnumIs/EnumTryAs generate undocumented methods.
pub enum Error {
    /// A name (`Namespace`, `Name`, or `LocalName`) could not be parsed.
    #[error("An error occurred trying to parse a name; error: {0}")]
    Name(#[from] NameParseError),

    /// The `url` crate failed to parse an IRI string.
    #[error("An error occurred parsing an IRI; error: {0}")]
    Url(#[from] UrlError),
}

///
/// Denotes an error generated by the various name related `FromStr` implementations.
///
#[derive(Debug, Error, EnumIs, EnumTryAs)]
#[allow(missing_docs)] // EnumIs/EnumTryAs generate undocumented methods.
pub enum NameParseError {
    /// The input string was empty.
    #[error("An empty string was passed, this is not a valid name")]
    EmptyString,
    /// The input contained a character that is not valid in the relevant
    /// SPARQL grammar production (`PN_PREFIX`, `PN_LOCAL`, etc.).
    #[error(
        "The parser encountered a character which is not valid according to its grammar; input: \"{0}\""
    )]
    InvalidCharacter(String),
    /// The input contained more `':'` separators than the grammar allows.
    #[error("The parser encountered more `':'` separator characters than expected; input: \"{0}\"")]
    TooManySeparators(String),
    /// A `Namespace` string is missing its trailing `':'` separator.
    #[error(
        "The Namespace string is missing a `':'` separator character at the end; input: \"{0}\""
    )]
    MissingSeparator(String),
}