diff options
Diffstat (limited to 'src/http')
| -rw-r--r-- | src/http/mod.rs | 26 | ||||
| -rw-r--r-- | src/http/render.rs | 12 |
2 files changed, 31 insertions, 7 deletions
diff --git a/src/http/mod.rs b/src/http/mod.rs index 4291021..60a1f2e 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -24,7 +24,8 @@ pub(crate) struct Req { } impl Req { - pub fn form(&self) -> &[(String, String)] { +/// Read by the route handlers, which are in this module; the word `form` in a test is a local parameter. + pub(crate) fn form(&self) -> &[(String, String)] { &self.form_pairs } pub fn form_get(&self, key: &str) -> Option<String> { @@ -95,11 +96,28 @@ impl Res { } } -pub struct Server { - pub handle: std::thread::JoinHandle<()>, - pub addr: String, +/// The real definition. The module is private, so this `pub` +/// is not a nameable path from outside; the alias below is the +/// only way to reach it, and the alias is what carries the +/// feature-conditional visibility. +mod server { + pub struct Server { + pub handle: std::thread::JoinHandle<()>, + pub addr: String, + } } +/// the handle to a running HTTP listener. `spawn` returns it and `main` holds it without naming the type; the test harness stores it in a field because it needs the bound address. +/// +/// `pub` only under `test-support`. Production reaches the type +/// through its own module and never names it from outside; the +/// outside reader that needs the name is a test. +#[cfg(feature = "test-support")] +pub use server::Server; + +#[cfg(not(feature = "test-support"))] +pub(crate) use server::Server; + pub fn spawn(cfg: Config, db: Db) -> std::io::Result<Server> { let server = tiny_http::Server::http(&cfg.bind) .map_err(|e| std::io::Error::other(e.to_string()))?; diff --git a/src/http/render.rs b/src/http/render.rs index 4482380..d513c2a 100644 --- a/src/http/render.rs +++ b/src/http/render.rs @@ -38,7 +38,9 @@ pub use page::Page; pub(crate) use page::Page; impl Page { - pub fn new(title: &str, csrf: String) -> Self { + /// Built by the route handlers, which are in this module; nothing outside + /// `http` constructs a page header. + pub(crate) fn new(title: &str, csrf: String) -> Self { Self { title: title.into(), flash: String::new(), @@ -181,7 +183,8 @@ pub use panel::Panel; pub(crate) use panel::Panel; impl Panel { - pub fn new(title: &str, body: String) -> Self { + /// Built by the route handlers, which are in this module. + pub(crate) fn new(title: &str, body: String) -> Self { Self { title: title.into(), empty: body.trim().is_empty(), @@ -329,7 +332,10 @@ pub(crate) struct BuildLite { } #[derive(Debug, Clone)] -pub struct BuildRow { +/// A row of the builds table as the templates render it. Filled and read +/// entirely inside `http`; the `BuildRow` other modules name is `db::builds::BuildRow`, +/// a different type that happens to share the name. +pub(crate) struct BuildRow { pub id: String, pub id_short: String, pub pkgbase: String, |
