🚚 Renombra ErrorParam
por ContextError
This commit is contained in:
parent
284d157931
commit
8912bbc8ec
3 changed files with 21 additions and 23 deletions
|
@ -8,8 +8,6 @@ pub use children::Children;
|
||||||
pub use children::{Child, ChildOp};
|
pub use children::{Child, ChildOp};
|
||||||
pub use children::{Typed, TypedOp};
|
pub use children::{Typed, TypedOp};
|
||||||
|
|
||||||
// **< HTML DOCUMENT CONTEXT >**********************************************************************
|
|
||||||
|
|
||||||
mod context;
|
mod context;
|
||||||
pub use context::{Context, ContextOp, Contextual, ErrorParam};
|
pub use context::{Context, ContextError, ContextOp, Contextual};
|
||||||
pub type FnPathByContext = fn(cx: &Context) -> &str;
|
pub type FnPathByContext = fn(cx: &Context) -> &str;
|
||||||
|
|
|
@ -33,14 +33,14 @@ pub enum ContextOp {
|
||||||
|
|
||||||
/// Errores de acceso a parámetros dinámicos del contexto.
|
/// Errores de acceso a parámetros dinámicos del contexto.
|
||||||
///
|
///
|
||||||
/// - [`ErrorParam::NotFound`]: la clave no existe.
|
/// - [`ContextError::ParamNotFound`]: la clave no existe.
|
||||||
/// - [`ErrorParam::TypeMismatch`]: la clave existe, pero el valor guardado no coincide con el tipo
|
/// - [`ContextError::ParamTypeMismatch`]: la clave existe, pero el valor guardado no coincide con
|
||||||
/// solicitado. Incluye nombre de la clave (`key`), tipo esperado (`expected`) y tipo realmente
|
/// el tipo solicitado. Incluye nombre de la clave (`key`), tipo esperado (`expected`) y tipo
|
||||||
/// guardado (`saved`) para facilitar el diagnóstico.
|
/// realmente guardado (`saved`) para facilitar el diagnóstico.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ErrorParam {
|
pub enum ContextError {
|
||||||
NotFound,
|
ParamNotFound,
|
||||||
TypeMismatch {
|
ParamTypeMismatch {
|
||||||
key: &'static str,
|
key: &'static str,
|
||||||
expected: &'static str,
|
expected: &'static str,
|
||||||
saved: &'static str,
|
saved: &'static str,
|
||||||
|
@ -290,8 +290,8 @@ impl Context {
|
||||||
/// Devuelve:
|
/// Devuelve:
|
||||||
///
|
///
|
||||||
/// - `Ok(&T)` si la clave existe y el tipo coincide.
|
/// - `Ok(&T)` si la clave existe y el tipo coincide.
|
||||||
/// - `Err(ErrorParam::NotFound)` si la clave no existe.
|
/// - `Err(ContextError::ParamNotFound)` si la clave no existe.
|
||||||
/// - `Err(ErrorParam::TypeMismatch)` si la clave existe pero el tipo no coincide.
|
/// - `Err(ContextError::ParamTypeMismatch)` si la clave existe pero el tipo no coincide.
|
||||||
///
|
///
|
||||||
/// # Ejemplos
|
/// # Ejemplos
|
||||||
///
|
///
|
||||||
|
@ -308,10 +308,10 @@ impl Context {
|
||||||
/// // Error de tipo:
|
/// // Error de tipo:
|
||||||
/// assert!(cx.get_param::<String>("usuario_id").is_err());
|
/// assert!(cx.get_param::<String>("usuario_id").is_err());
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get_param<T: 'static>(&self, key: &'static str) -> Result<&T, ErrorParam> {
|
pub fn get_param<T: 'static>(&self, key: &'static str) -> Result<&T, ContextError> {
|
||||||
let (any, type_name) = self.params.get(key).ok_or(ErrorParam::NotFound)?;
|
let (any, type_name) = self.params.get(key).ok_or(ContextError::ParamNotFound)?;
|
||||||
any.downcast_ref::<T>()
|
any.downcast_ref::<T>()
|
||||||
.ok_or_else(|| ErrorParam::TypeMismatch {
|
.ok_or_else(|| ContextError::ParamTypeMismatch {
|
||||||
key,
|
key,
|
||||||
expected: TypeInfo::FullName.of::<T>(),
|
expected: TypeInfo::FullName.of::<T>(),
|
||||||
saved: type_name,
|
saved: type_name,
|
||||||
|
@ -323,8 +323,8 @@ impl Context {
|
||||||
/// Devuelve:
|
/// Devuelve:
|
||||||
///
|
///
|
||||||
/// - `Ok(T)` si la clave existía y el tipo coincide.
|
/// - `Ok(T)` si la clave existía y el tipo coincide.
|
||||||
/// - `Err(ErrorParam::NotFound)` si la clave no existe.
|
/// - `Err(ContextError::ParamNotFound)` si la clave no existe.
|
||||||
/// - `Err(ErrorParam::TypeMismatch)` si el tipo no coincide.
|
/// - `Err(ContextError::ParamTypeMismatch)` si el tipo no coincide.
|
||||||
///
|
///
|
||||||
/// # Ejemplos
|
/// # Ejemplos
|
||||||
///
|
///
|
||||||
|
@ -341,12 +341,12 @@ impl Context {
|
||||||
/// // Error de tipo:
|
/// // Error de tipo:
|
||||||
/// assert!(cx.take_param::<i32>("titulo").is_err());
|
/// assert!(cx.take_param::<i32>("titulo").is_err());
|
||||||
/// ```
|
/// ```
|
||||||
pub fn take_param<T: 'static>(&mut self, key: &'static str) -> Result<T, ErrorParam> {
|
pub fn take_param<T: 'static>(&mut self, key: &'static str) -> Result<T, ContextError> {
|
||||||
let (boxed, saved) = self.params.remove(key).ok_or(ErrorParam::NotFound)?;
|
let (boxed, saved) = self.params.remove(key).ok_or(ContextError::ParamNotFound)?;
|
||||||
boxed
|
boxed
|
||||||
.downcast::<T>()
|
.downcast::<T>()
|
||||||
.map(|b| *b)
|
.map(|b| *b)
|
||||||
.map_err(|_| ErrorParam::TypeMismatch {
|
.map_err(|_| ContextError::ParamTypeMismatch {
|
||||||
key,
|
key,
|
||||||
expected: TypeInfo::FullName.of::<T>(),
|
expected: TypeInfo::FullName.of::<T>(),
|
||||||
saved,
|
saved,
|
||||||
|
|
|
@ -31,12 +31,12 @@ pub type ContextOp = crate::core::component::ContextOp;
|
||||||
)]
|
)]
|
||||||
pub trait Contextual: crate::core::component::Contextual {}
|
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(
|
#[deprecated(
|
||||||
since = "0.5.0",
|
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.
|
/// **Obsoleto desde la versión 0.5.0**: usar [`ContextOp`] en su lugar.
|
||||||
#[deprecated(since = "0.5.0", note = "Use `ContextOp` instead")]
|
#[deprecated(since = "0.5.0", note = "Use `ContextOp` instead")]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue