Skip to content

Commit 7a13bd0

Browse files
authored
v0.0.5
1 parent 8674bd9 commit 7a13bd0

11 files changed

Lines changed: 43 additions & 863 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ resolver = "2"
55
[workspace.package]
66
rust-version = "1.90.0"
77
edition = "2024"
8-
version = "0.0.4"
8+
version = "0.0.5"
99
license = "GPL-3.0"
1010
repository = "https://github.com/rm-dr/servable"
1111
readme = "README.md"
@@ -44,7 +44,7 @@ mutex_atomic = "deny"
4444
needless_raw_strings = "deny"
4545
str_to_string = "deny"
4646
string_add = "deny"
47-
string_to_string = "deny"
47+
implicit_clone = "deny"
4848
use_debug = "allow"
4949
verbose_file_reads = "deny"
5050
large_types_passed_by_value = "deny"
@@ -74,6 +74,7 @@ axum = "0.8"
7474
chrono = "0.4"
7575
image = "0.25"
7676
maud = "0.27"
77+
mime = "0.3"
7778
rand = "0.9"
7879
serde = { version = "1.0", features = ["derive"] }
7980
serde_urlencoded = "0.7"

crates/servable/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ serde_urlencoded = { workspace = true }
2323
tower = { workspace = true }
2424
tracing = { workspace = true }
2525
rand = { workspace = true }
26+
mime = { workspace = true }
2627

2728
tokio = { workspace = true, optional = true }
2829
image = { workspace = true, optional = true }

crates/servable/README.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async fn main() {
3232
"/hello",
3333
StaticAsset {
3434
bytes: b"Hello, World!",
35-
mime: MimeType::Text,
35+
mime: mime::TEXT_PLAIN
3636
},
3737
);
3838
@@ -56,11 +56,11 @@ The `Servable` trait is the foundation of this stack. \
5656

5757
- `StaticAsset`, for static files like CSS, JavaScript, images, or plain bytes:
5858
```rust
59-
use servable::{StaticAsset, mime::MimeType};
59+
use servable::{StaticAsset};
6060

6161
let asset = StaticAsset {
6262
bytes: b"body { color: red; }",
63-
mime: MimeType::Css,
63+
mime: mime::TEXT_CSS,
6464
ttl: StaticAsset::DEFAULT_TTL
6565
};
6666
```
@@ -102,11 +102,11 @@ The `Servable` trait is the foundation of this stack. \
102102
A `ServableRouter` exposes a collection of `Servable`s under different routes. It implements `tower`'s `Service` trait, and can be easily be converted into an Axum `Router`. Construct one as follows:
103103

104104
```rust
105-
# use servable::{ServableRouter, StaticAsset, mime::MimeType};
106-
# let home_page = StaticAsset { bytes: b"home", mime: MimeType::Html, ttl: StaticAsset::DEFAULT_TTL};
107-
# let about_page = StaticAsset { bytes: b"about", mime: MimeType::Html, ttl: StaticAsset::DEFAULT_TTL };
108-
# let stylesheet = StaticAsset { bytes: b"css", mime: MimeType::Css, ttl: StaticAsset::DEFAULT_TTL };
109-
# let custom_404_page = StaticAsset { bytes: b"404", mime: MimeType::Html, ttl: StaticAsset::DEFAULT_TTL };
105+
# use servable::{ServableRouter, StaticAsset};
106+
# let home_page = StaticAsset { bytes: b"home", mime: mime::TEXT_HTML, ttl: StaticAsset::DEFAULT_TTL};
107+
# let about_page = StaticAsset { bytes: b"about", mime: mime::TEXT_HTML, ttl: StaticAsset::DEFAULT_TTL };
108+
# let stylesheet = StaticAsset { bytes: b"css", mime: mime::TEXT_CSS, ttl: StaticAsset::DEFAULT_TTL };
109+
# let custom_404_page = StaticAsset { bytes: b"404", mime: mime::TEXT_HTML, ttl: StaticAsset::DEFAULT_TTL };
110110
let route = ServableRouter::new()
111111
.add_page("/", home_page)
112112
.add_page("/about", about_page)
@@ -121,13 +121,13 @@ let route = ServableRouter::new()
121121

122122
When `image` is enabled, the image below...
123123
```rust
124-
# use servable::{ServableRouter, StaticAsset, mime::MimeType};
124+
# use servable::{ServableRouter, StaticAsset};
125125
let route = ServableRouter::new()
126126
.add_page(
127127
"/image.png",
128128
StaticAsset {
129129
bytes: b"fake image data",
130-
mime: MimeType::Png,
130+
mime: mime::IMAGE_PNG,
131131
ttl: StaticAsset::DEFAULT_TTL
132132
}
133133
);
@@ -184,13 +184,12 @@ whenever the server is restarted:
184184
```rust
185185
use chrono::TimeDelta;
186186
use servable::{HtmlPage, CACHE_BUST_STR, ServableWithRoute, StaticAsset, ServableRouter};
187-
use servable::mime::MimeType;
188187

189188
pub static HTMX: ServableWithRoute<StaticAsset> = ServableWithRoute::new(
190189
|| format!("/{}/main.css", *CACHE_BUST_STR),
191190
StaticAsset {
192191
bytes: "div{}".as_bytes(),
193-
mime: MimeType::Css,
192+
mime: mime::TEXT_CSS,
194193
ttl: StaticAsset::DEFAULT_TTL,
195194
},
196195
);

crates/servable/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
// and needs a different relative path than cargo build.
55
// https://github.com/rust-lang/cargo/issues/13309
66

7-
pub mod mime;
8-
97
mod types;
108

119
use rand::{Rng, distr::Alphanumeric};
@@ -47,7 +45,7 @@ pub static CACHE_BUST_STR: std::sync::LazyLock<String> = std::sync::LazyLock::ne
4745
#[cfg(feature = "htmx-2.0.8")]
4846
pub const HTMX_2_0_8: servable::StaticAsset = servable::StaticAsset {
4947
bytes: include_str!("../htmx/htmx-2.0.8.min.js").as_bytes(),
50-
mime: mime::MimeType::Javascript,
48+
mime: mime::TEXT_JAVASCRIPT,
5149
ttl: StaticAsset::DEFAULT_TTL,
5250
};
5351

@@ -57,6 +55,6 @@ pub const HTMX_2_0_8: servable::StaticAsset = servable::StaticAsset {
5755
#[cfg(feature = "htmx-2.0.8")]
5856
pub const EXT_JSON_1_19_12: servable::StaticAsset = servable::StaticAsset {
5957
bytes: include_str!("../htmx/json-enc-1.9.12.js").as_bytes(),
60-
mime: mime::MimeType::Javascript,
58+
mime: mime::TEXT_JAVASCRIPT,
6159
ttl: StaticAsset::DEFAULT_TTL,
6260
};

0 commit comments

Comments
 (0)