summaryrefslogtreecommitdiff
path: root/src/cli.rs
diff options
context:
space:
mode:
authorojacobson <ojacobson@noreply.codeberg.org>2025-07-23 00:23:10 +0200
committerojacobson <ojacobson@noreply.codeberg.org>2025-07-23 00:23:10 +0200
commitaec3eaeebd37bce9ab4dad14e7e86ef0db8f0c2d (patch)
tree98b1c0f92a35d91dafc2dd7b56b32260a3d2b6d9 /src/cli.rs
parent64639acbab02aa4103cbe44199e38991269b2137 (diff)
parent792de8e49fa8a3c04bfb747adadf71572d753055 (diff)
Fix some minor weirdness when Pilcrow is (unwisely) used as a library.
Pilcrow isn't meant to be used as a library, and the only public interface the `pilcrow` lib crate exposes is the CLI entry point. However, we will likely be publishing Pilcrow via crates.io (among other options) one day, and so it will _be usable_ as a library if someone's desperate enough to try. To that end, let's try to be good citizens. This change fixes two issues: * The docs contained links to internal items, which are not actually included in the library documentation. The links are simply removed; the uses of those items were already private anyways. * The CLI `Error` type is no longer part of the public interface, using `impl Trait` (`impl std::error::Error`) shenanigans to hide the error type from callers. (To be clear, this would be _extremely_ rude in code intended for library use.) This frees us up to change the structure of the error type - or to replace it entirely - without making the world's most pedantic semver change in the process. Merges lib-crate-weirdness into main.
Diffstat (limited to 'src/cli.rs')
-rw-r--r--src/cli.rs13
1 files changed, 4 insertions, 9 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 57c5c07..703bf19 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -84,11 +84,10 @@ impl Args {
/// # Errors
///
/// Will return `Err` if the server is unable to start, or terminates
- /// prematurely. The specific [`Error`] variant will expose the cause
+ /// prematurely. The returned error contains a user-facing explanation
/// of the failure.
- pub async fn run(self) -> Result<(), Error> {
+ pub async fn run(self) -> Result<(), impl std::error::Error> {
self.umask.set();
-
let pool = self.pool().await?;
let app = App::from(pool);
@@ -104,7 +103,7 @@ impl Args {
println!("{started_msg}");
serve.await?;
- Ok(())
+ Result::<_, Error>::Ok(())
}
async fn listener(&self) -> io::Result<net::TcpListener> {
@@ -138,14 +137,10 @@ fn started_msg(listener: &net::TcpListener) -> io::Result<String> {
Ok(format!("listening on http://{local_addr}/"))
}
-/// Errors that can be raised by [`Args::run`].
#[derive(Debug, thiserror::Error)]
#[error(transparent)]
-pub enum Error {
- /// Failure due to `io::Error`. See [`io::Error`].
+enum Error {
Io(#[from] io::Error),
- /// Failure due to a database initialization error. See [`db::Error`].
Database(#[from] db::Error),
- /// Failure due to invalid umask-related options.
Umask(#[from] umask::Error),
}