♻️ (statics): Renombra StaticResource a StaticFile

Clarifica la distinción entre un fichero estático individual
(`StaticFile`) y el contenedor de varios ficheros (`StaticResources`).
This commit is contained in:
Manuel Cillero 2026-06-01 22:02:23 +02:00
parent b1ce79c78f
commit 2c52af4b9d
6 changed files with 32 additions and 37 deletions

View file

@ -134,26 +134,26 @@ pub const PAGETOP_VERSION: &str = env!("CARGO_PKG_VERSION");
pub use pagetop_macros::{AutoDefault, builder_fn, html, main, test};
pub use pagetop_statics::{StaticResource, resource};
pub use pagetop_statics::{StaticFile, resource};
pub use getter_methods::Getters;
/// Contenedor para un conjunto de recursos embebidos.
#[derive(AutoDefault)]
pub struct StaticResources {
bundle: HashMap<&'static str, StaticResource>,
bundle: HashMap<&'static str, StaticFile>,
}
impl StaticResources {
/// Crea un contenedor para un conjunto de recursos generado por `build.rs` (consultar
/// [`pagetop_build`](https://docs.rs/pagetop-build)).
pub fn new(bundle: HashMap<&'static str, StaticResource>) -> Self {
pub fn new(bundle: HashMap<&'static str, StaticFile>) -> Self {
Self { bundle }
}
}
impl Deref for StaticResources {
type Target = HashMap<&'static str, StaticResource>;
type Target = HashMap<&'static str, StaticFile>;
fn deref(&self) -> &Self::Target {
&self.bundle

View file

@ -5,6 +5,8 @@
//! el módulo `http` para tipos de bajo nivel como `StatusCode`, `HeaderName` o `Method`. También
//! ofrece utilidades para servir archivos estáticos, [`ServeDir`] y [`ServeEmbedded`].
use crate::StaticFile;
use std::collections::HashMap;
use std::convert::Infallible;
use std::task::{Context, Poll};
@ -25,10 +27,6 @@ pub use axum::response::{IntoResponse, Response};
// Operaciones HTTP para registrar rutas.
pub use axum::routing::{delete, get, patch, post, put};
// Servicios para archivos estáticos (disco y embebidos).
pub use pagetop_statics::StaticResource;
pub use tower_http::services::ServeDir;
// **< HttpRequest >********************************************************************************
/// Representa una petición HTTP.
@ -91,6 +89,11 @@ impl<S: Send + Sync> FromRequestParts<S> for HttpRequest {
}
}
// **< ServeDir >***********************************************************************************
// Servicio para archivos estáticos en disco.
pub use tower_http::services::ServeDir;
// **< ServeEmbedded >******************************************************************************
/// Servicio para archivos estáticos embebidos en el binario.
@ -104,12 +107,12 @@ impl<S: Send + Sync> FromRequestParts<S> for HttpRequest {
/// recursos con un [`Arc`](std::sync::Arc) para evitar copias innecesarias.
#[derive(Clone)]
pub struct ServeEmbedded {
files: std::sync::Arc<HashMap<&'static str, StaticResource>>,
files: std::sync::Arc<HashMap<&'static str, StaticFile>>,
}
impl ServeEmbedded {
/// Crea un nuevo servicio a partir del mapa de recursos embebidos generado por `build.rs`.
pub fn new(files: HashMap<&'static str, StaticResource>) -> Self {
pub fn new(files: HashMap<&'static str, StaticFile>) -> Self {
Self {
files: std::sync::Arc::new(files),
}