diff --git a/src/core/component.rs b/src/core/component.rs index a002e3d..be9bbad 100644 --- a/src/core/component.rs +++ b/src/core/component.rs @@ -8,8 +8,6 @@ pub use children::Children; pub use children::{Child, ChildOp}; pub use children::{Typed, TypedOp}; -// **< HTML DOCUMENT CONTEXT >********************************************************************** - mod context; -pub use context::{Context, ContextOp, Contextual, ErrorParam}; +pub use context::{Context, ContextError, ContextOp, Contextual}; pub type FnPathByContext = fn(cx: &Context) -> &str; diff --git a/src/core/component/context.rs b/src/core/component/context.rs index 9333e48..9dad7f5 100644 --- a/src/core/component/context.rs +++ b/src/core/component/context.rs @@ -33,14 +33,14 @@ pub enum ContextOp { /// Errores de acceso a parámetros dinámicos del contexto. /// -/// - [`ErrorParam::NotFound`]: la clave no existe. -/// - [`ErrorParam::TypeMismatch`]: la clave existe, pero el valor guardado no coincide con el tipo -/// solicitado. Incluye nombre de la clave (`key`), tipo esperado (`expected`) y tipo realmente -/// guardado (`saved`) para facilitar el diagnóstico. +/// - [`ContextError::ParamNotFound`]: la clave no existe. +/// - [`ContextError::ParamTypeMismatch`]: la clave existe, pero el valor guardado no coincide con +/// el tipo solicitado. Incluye nombre de la clave (`key`), tipo esperado (`expected`) y tipo +/// realmente guardado (`saved`) para facilitar el diagnóstico. #[derive(Debug)] -pub enum ErrorParam { - NotFound, - TypeMismatch { +pub enum ContextError { + ParamNotFound, + ParamTypeMismatch { key: &'static str, expected: &'static str, saved: &'static str, @@ -290,8 +290,8 @@ impl Context { /// Devuelve: /// /// - `Ok(&T)` si la clave existe y el tipo coincide. - /// - `Err(ErrorParam::NotFound)` si la clave no existe. - /// - `Err(ErrorParam::TypeMismatch)` si la clave existe pero el tipo no coincide. + /// - `Err(ContextError::ParamNotFound)` si la clave no existe. + /// - `Err(ContextError::ParamTypeMismatch)` si la clave existe pero el tipo no coincide. /// /// # Ejemplos /// @@ -308,10 +308,10 @@ impl Context { /// // Error de tipo: /// assert!(cx.get_param::("usuario_id").is_err()); /// ``` - pub fn get_param(&self, key: &'static str) -> Result<&T, ErrorParam> { - let (any, type_name) = self.params.get(key).ok_or(ErrorParam::NotFound)?; + pub fn get_param(&self, key: &'static str) -> Result<&T, ContextError> { + let (any, type_name) = self.params.get(key).ok_or(ContextError::ParamNotFound)?; any.downcast_ref::() - .ok_or_else(|| ErrorParam::TypeMismatch { + .ok_or_else(|| ContextError::ParamTypeMismatch { key, expected: TypeInfo::FullName.of::(), saved: type_name, @@ -323,8 +323,8 @@ impl Context { /// Devuelve: /// /// - `Ok(T)` si la clave existía y el tipo coincide. - /// - `Err(ErrorParam::NotFound)` si la clave no existe. - /// - `Err(ErrorParam::TypeMismatch)` si el tipo no coincide. + /// - `Err(ContextError::ParamNotFound)` si la clave no existe. + /// - `Err(ContextError::ParamTypeMismatch)` si el tipo no coincide. /// /// # Ejemplos /// @@ -341,12 +341,12 @@ impl Context { /// // Error de tipo: /// assert!(cx.take_param::("titulo").is_err()); /// ``` - pub fn take_param(&mut self, key: &'static str) -> Result { - let (boxed, saved) = self.params.remove(key).ok_or(ErrorParam::NotFound)?; + pub fn take_param(&mut self, key: &'static str) -> Result { + let (boxed, saved) = self.params.remove(key).ok_or(ContextError::ParamNotFound)?; boxed .downcast::() .map(|b| *b) - .map_err(|_| ErrorParam::TypeMismatch { + .map_err(|_| ContextError::ParamTypeMismatch { key, expected: TypeInfo::FullName.of::(), saved, diff --git a/src/html.rs b/src/html.rs index 079811a..a86c9f7 100644 --- a/src/html.rs +++ b/src/html.rs @@ -31,12 +31,12 @@ pub type ContextOp = crate::core::component::ContextOp; )] pub trait Contextual: crate::core::component::Contextual {} -/// **Obsoleto desde la versión 0.5.0**: usar [`core::component::ErrorParam`] en su lugar. +/// **Obsoleto desde la versión 0.5.0**: usar [`core::component::ContextError`] en su lugar. #[deprecated( since = "0.5.0", - note = "Moved to `pagetop::core::component::ErrorParam`" + note = "Moved to `pagetop::core::component::ContextError`" )] -pub type ErrorParam = crate::core::component::ErrorParam; +pub type ContextError = crate::core::component::ContextError; /// **Obsoleto desde la versión 0.5.0**: usar [`ContextOp`] en su lugar. #[deprecated(since = "0.5.0", note = "Use `ContextOp` instead")]