Skip to content

Commit 8dc09f2

Browse files
committed
Fix #123: remove one unused error variant and make types crate public
1 parent e1edb4b commit 8dc09f2

File tree

18 files changed

+50
-53
lines changed

18 files changed

+50
-53
lines changed

src/assets.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::highlight::Theme;
1111

1212
/// An asset associated with a MIME type.
1313
#[derive(Clone)]
14-
pub struct Asset {
14+
pub(crate) struct Asset {
1515
/// Route that this will be served under.
1616
pub route: String,
1717
/// MIME type of this asset determined for the `ContentType` response header.
@@ -22,7 +22,7 @@ pub struct Asset {
2222

2323
/// Asset kind.
2424
#[derive(Copy, Clone)]
25-
pub enum Kind {
25+
pub(crate) enum Kind {
2626
Css,
2727
Js,
2828
}
@@ -77,7 +77,7 @@ impl Asset {
7777
}
7878

7979
/// Collection of light and dark CSS and main UI style CSS derived from them.
80-
pub struct Css {
80+
pub(crate) struct Css {
8181
/// Main UI CSS stylesheet.
8282
pub style: Asset,
8383
/// Light theme colors.

src/cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ use std::sync::{Arc, Mutex};
99

1010
/// Cache based on identifier and format.
1111
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
12-
pub struct Key {
12+
pub(crate) struct Key {
1313
pub id: Id,
1414
pub ext: String,
1515
}
1616

1717
/// Stores formatted HTML.
1818
#[derive(Clone)]
19-
pub struct Cache {
19+
pub(crate) struct Cache {
2020
inner: Arc<Mutex<SizedCache<Key, Html>>>,
2121
}
2222

src/crypto.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ static CONFIG: LazyLock<argon2::Config> = LazyLock::new(|| argon2::Config {
1919
static SALT: LazyLock<String> = LazyLock::new(env::password_hash_salt);
2020

2121
/// Encrypted data item.
22-
pub struct Encrypted {
22+
pub(crate) struct Encrypted {
2323
/// Encrypted ciphertext.
2424
pub ciphertext: Vec<u8>,
2525
/// Nonce used for encryption.
2626
pub nonce: Vec<u8>,
2727
}
2828

2929
#[derive(Clone)]
30-
pub struct Password(Vec<u8>);
30+
pub(crate) struct Password(Vec<u8>);
3131

3232
/// Plaintext bytes to be encrypted.
33-
pub struct Plaintext(Vec<u8>);
33+
pub(crate) struct Plaintext(Vec<u8>);
3434

3535
impl From<Vec<u8>> for Password {
3636
fn from(value: Vec<u8>) -> Self {

src/db.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ static MIGRATIONS: LazyLock<Migrations> = LazyLock::new(|| {
4949

5050
/// Our main database and integrated cache.
5151
#[derive(Clone)]
52-
pub struct Database {
52+
pub(crate) struct Database {
5353
conn: Arc<Mutex<Connection>>,
5454
}
5555

5656
/// Database opening modes
5757
#[derive(Debug)]
58-
pub enum Open {
58+
pub(crate) enum Open {
5959
/// Open in-memory database that is wiped after reload
6060
Memory,
6161
/// Open database from given path
6262
Path(PathBuf),
6363
}
6464

6565
/// Module with types for insertion.
66-
pub mod write {
66+
pub(crate) mod write {
6767
use crate::crypto::{Encrypted, Password, Plaintext};
6868
use crate::errors::Error;
6969
use async_compression::tokio::bufread::ZstdEncoder;
@@ -74,7 +74,7 @@ pub mod write {
7474

7575
/// An uncompressed entry to be inserted into the database.
7676
#[derive(Default, Debug, Serialize, Deserialize)]
77-
pub struct Entry {
77+
pub(crate) struct Entry {
7878
/// Content
7979
pub text: String,
8080
/// File extension
@@ -92,15 +92,15 @@ pub mod write {
9292
}
9393

9494
/// A compressed entry to be inserted.
95-
pub struct CompressedEntry {
95+
pub(crate) struct CompressedEntry {
9696
/// Original data
9797
entry: Entry,
9898
/// Compressed data
9999
data: Vec<u8>,
100100
}
101101

102102
/// An entry that might be encrypted.
103-
pub struct DatabaseEntry {
103+
pub(crate) struct DatabaseEntry {
104104
/// Original data
105105
pub entry: Entry,
106106
/// Compressed and potentially encrypted data
@@ -147,7 +147,7 @@ pub mod write {
147147
}
148148

149149
/// Module with types for reading from the database.
150-
pub mod read {
150+
pub(crate) mod read {
151151
use crate::crypto::{Encrypted, Password};
152152
use crate::errors::Error;
153153
use async_compression::tokio::bufread::ZstdDecoder;
@@ -156,7 +156,7 @@ pub mod read {
156156

157157
/// A raw entry as read from the database.
158158
#[derive(Debug)]
159-
pub struct DatabaseEntry {
159+
pub(crate) struct DatabaseEntry {
160160
/// Compressed and potentially encrypted data
161161
pub data: Vec<u8>,
162162
/// Entry is expired
@@ -173,7 +173,7 @@ pub mod read {
173173

174174
/// Potentially decrypted but still compressed entry
175175
#[derive(Debug)]
176-
pub struct CompressedReadEntry {
176+
pub(crate) struct CompressedReadEntry {
177177
/// Compressed data
178178
data: Vec<u8>,
179179
/// Entry must be deleted
@@ -186,7 +186,7 @@ pub mod read {
186186

187187
/// Uncompressed entry
188188
#[derive(Debug)]
189-
pub struct UmcompressedEntry {
189+
pub(crate) struct UmcompressedEntry {
190190
/// Content
191191
pub text: String,
192192
/// Entry must be deleted
@@ -199,7 +199,7 @@ pub mod read {
199199

200200
/// Uncompressed, decrypted data read from the database.
201201
#[derive(Debug)]
202-
pub struct Data {
202+
pub(crate) struct Data {
203203
/// Content
204204
pub text: String,
205205
/// User identifier that inserted the entry
@@ -210,7 +210,7 @@ pub mod read {
210210

211211
/// Potentially deleted or non-existent expired entry.
212212
#[derive(Debug)]
213-
pub enum Entry {
213+
pub(crate) enum Entry {
214214
/// Entry found and still available.
215215
Regular(Data),
216216
/// Entry burned.

src/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const VAR_THEME: &str = "WASTEBIN_THEME";
2020
const VAR_PASSWORD_SALT: &str = "WASTEBIN_PASSWORD_SALT";
2121

2222
#[derive(thiserror::Error, Debug)]
23-
pub enum Error {
23+
pub(crate) enum Error {
2424
#[error("failed to parse {VAR_CACHE_SIZE}, expected number of elements: {0}")]
2525
CacheSize(ParseIntError),
2626
#[error("failed to parse {VAR_DATABASE_PATH}, contains non-Unicode data")]

src/errors.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use serde::Serialize;
44
use std::num::TryFromIntError;
55

66
#[derive(thiserror::Error, Debug)]
7-
pub enum Error {
7+
pub(crate) enum Error {
88
#[error("axum http error: {0}")]
99
Axum(#[from] axum::http::Error),
1010
#[error("not allowed to delete")]
@@ -33,8 +33,6 @@ pub enum Error {
3333
CookieParsing(String),
3434
#[error("could not generate QR code: {0}")]
3535
QrCode(#[from] qrcodegen::DataTooLong),
36-
#[error("could not find Host header to generate QR code URL")]
37-
NoHost,
3836
#[error("could not parse URL: {0}")]
3937
UrlParsing(#[from] url::ParseError),
4038
#[error("argon2 error: {0}")]
@@ -48,19 +46,18 @@ pub enum Error {
4846
}
4947

5048
#[derive(Serialize)]
51-
pub struct JsonError {
49+
pub(crate) struct JsonError {
5250
pub message: String,
5351
}
5452

5553
/// Response carrying a status code and the error message as JSON.
56-
pub type JsonErrorResponse = (StatusCode, Json<JsonError>);
54+
pub(crate) type JsonErrorResponse = (StatusCode, Json<JsonError>);
5755

5856
impl From<Error> for StatusCode {
5957
fn from(err: Error) -> Self {
6058
match err {
6159
Error::NotFound => StatusCode::NOT_FOUND,
62-
Error::NoHost
63-
| Error::IllegalCharacters
60+
Error::IllegalCharacters
6461
| Error::WrongSize
6562
| Error::UrlParsing(_)
6663
| Error::NoPassword

src/handlers/extract.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use serde::Deserialize;
66

77
/// Theme extracted from the `pref` cookie.
88
#[derive(Debug, Deserialize, Clone)]
9-
pub enum Theme {
9+
pub(crate) enum Theme {
1010
#[serde(rename = "dark")]
1111
Dark,
1212
#[serde(rename = "light")]
@@ -15,14 +15,14 @@ pub enum Theme {
1515

1616
/// Theme preference for use in shared [`axum::extract::Query`]'s.
1717
#[derive(Debug, Deserialize)]
18-
pub struct Preference {
18+
pub(crate) struct Preference {
1919
pub pref: Theme,
2020
}
2121

22-
pub struct Password(pub crypto::Password);
22+
pub(crate) struct Password(pub crypto::Password);
2323

2424
/// Password header to encrypt a paste.
25-
pub const PASSWORD_HEADER_NAME: http::HeaderName =
25+
pub(crate) const PASSWORD_HEADER_NAME: http::HeaderName =
2626
http::HeaderName::from_static("wastebin-password");
2727

2828
impl std::fmt::Display for Theme {

src/handlers/html/burn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub async fn get(
3737
/// Burn page shown if "burn-after-reading" was selected during insertion.
3838
#[derive(Template)]
3939
#[template(path = "burn.html", escape = "none")]
40-
pub struct Burn {
40+
pub(crate) struct Burn {
4141
page: Page,
4242
key: Key,
4343
code: qrcodegen::QrCode,

src/handlers/html/index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub async fn get(
1818
/// Index page displaying a form for paste insertion and a selection box for languages.
1919
#[derive(Template)]
2020
#[template(path = "index.html")]
21-
pub struct Index {
21+
pub(crate) struct Index {
2222
page: Page,
2323
theme: Option<Theme>,
2424
highlighter: Highlighter,

src/handlers/html/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use axum::http::StatusCode;
1111
/// Error page showing a message.
1212
#[derive(Template)]
1313
#[template(path = "error.html")]
14-
pub struct Error {
14+
pub(crate) struct Error {
1515
pub page: Page,
1616
pub theme: Option<Theme>,
1717
pub description: String,
@@ -20,14 +20,14 @@ pub struct Error {
2020
/// Page showing password input.
2121
#[derive(Template)]
2222
#[template(path = "encrypted.html")]
23-
pub struct PasswordInput {
23+
pub(crate) struct PasswordInput {
2424
pub page: Page,
2525
pub theme: Option<Theme>,
2626
pub id: String,
2727
}
2828

2929
/// Error response carrying a status code and the page itself.
30-
pub type ErrorResponse = (StatusCode, Error);
30+
pub(crate) type ErrorResponse = (StatusCode, Error);
3131

3232
/// Create an error response from `error` consisting of [`StatusCode`] derive from `error` as well
3333
/// as a rendered page with a description.

0 commit comments

Comments
 (0)