🚚 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::{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;
|
||||
|
|
|
@ -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::<String>("usuario_id").is_err());
|
||||
/// ```
|
||||
pub fn get_param<T: 'static>(&self, key: &'static str) -> Result<&T, ErrorParam> {
|
||||
let (any, type_name) = self.params.get(key).ok_or(ErrorParam::NotFound)?;
|
||||
pub fn get_param<T: 'static>(&self, key: &'static str) -> Result<&T, ContextError> {
|
||||
let (any, type_name) = self.params.get(key).ok_or(ContextError::ParamNotFound)?;
|
||||
any.downcast_ref::<T>()
|
||||
.ok_or_else(|| ErrorParam::TypeMismatch {
|
||||
.ok_or_else(|| ContextError::ParamTypeMismatch {
|
||||
key,
|
||||
expected: TypeInfo::FullName.of::<T>(),
|
||||
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::<i32>("titulo").is_err());
|
||||
/// ```
|
||||
pub fn take_param<T: 'static>(&mut self, key: &'static str) -> Result<T, ErrorParam> {
|
||||
let (boxed, saved) = self.params.remove(key).ok_or(ErrorParam::NotFound)?;
|
||||
pub fn take_param<T: 'static>(&mut self, key: &'static str) -> Result<T, ContextError> {
|
||||
let (boxed, saved) = self.params.remove(key).ok_or(ContextError::ParamNotFound)?;
|
||||
boxed
|
||||
.downcast::<T>()
|
||||
.map(|b| *b)
|
||||
.map_err(|_| ErrorParam::TypeMismatch {
|
||||
.map_err(|_| ContextError::ParamTypeMismatch {
|
||||
key,
|
||||
expected: TypeInfo::FullName.of::<T>(),
|
||||
saved,
|
||||
|
|
|
@ -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")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue