pub mod casting;
pub mod coercion;
pub mod inference;
pub mod validation;
use std::fmt;
pub use self::casting::TypeCaster;
pub use self::coercion::{CoercionStrategy, TypeCoercion};
pub use self::inference::TypeInferenceEngine as TypeInference;
pub use self::validation::TypeValidator;
pub use crate::ast::ast::{GraphTypeSpec, TypeSpec as GqlType};
#[derive(Debug, Clone)]
pub enum TypeError {
#[allow(dead_code)] IncompatibleTypes(String, String),
#[allow(dead_code)] InvalidCast(String, String),
#[allow(dead_code)] TypeMismatch {
expected: String,
actual: String,
},
InvalidTypeSpecification(String),
#[allow(dead_code)] NullabilityViolation(String),
#[allow(dead_code)] CollectionTypeMismatch(String),
#[allow(dead_code)] GraphSchemaViolation(String),
#[allow(dead_code)] NumericOverflow(String),
#[allow(dead_code)] UnknownType(String),
}
impl fmt::Display for TypeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TypeError::IncompatibleTypes(t1, t2) => {
write!(f, "Incompatible types: {} and {}", t1, t2)
}
TypeError::InvalidCast(from, to) => {
write!(f, "Cannot cast from {} to {}", from, to)
}
TypeError::TypeMismatch { expected, actual } => {
write!(f, "Type mismatch: expected {}, got {}", expected, actual)
}
TypeError::InvalidTypeSpecification(msg) => {
write!(f, "Invalid type specification: {}", msg)
}
TypeError::NullabilityViolation(msg) => {
write!(f, "Nullability violation: {}", msg)
}
TypeError::CollectionTypeMismatch(msg) => {
write!(f, "Collection type mismatch: {}", msg)
}
TypeError::GraphSchemaViolation(msg) => {
write!(f, "Graph schema violation: {}", msg)
}
TypeError::NumericOverflow(msg) => {
write!(f, "Numeric overflow: {}", msg)
}
TypeError::UnknownType(name) => {
write!(f, "Unknown type: {}", name)
}
}
}
}
impl std::error::Error for TypeError {}
pub type TypeResult<T> = Result<T, TypeError>;