Update random (#82)

This commit is contained in:
Noa Aarts 2025-03-08 10:24:37 +01:00 committed by GitHub
commit 3525f4c40e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 326 additions and 230 deletions

499
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -5,26 +5,26 @@ edition = "2021"
license = "AGPL-3.0"
[dependencies]
async-trait = "0.1.83"
atoi_radix10 = { version = "0.0.1", optional = true }
axum = { version = "0.7.7", features = ["ws"] }
axum-embed = "0.1.0"
axum-extra = { version = "0.9.4", features = ["typed-header"] }
axum-streams = "0.19.0"
bytes = "1.6.0"
chrono = "0.4.38"
futures = "0.3.31"
headers = "0.4.0"
image = "0.25.2"
async-trait = "*"
atoi_radix10 = { version = "*", optional = true }
axum = { version = "*", features = ["ws"] }
axum-embed = "*"
axum-extra = { version = "*", features = ["typed-header"] }
axum-streams = "*"
bytes = "*"
chrono = "*"
futures = "*"
headers = "*"
image = "*"
rand = "*"
rust-embed = "8.5.0"
serde = { version = "1.0.210", features = ["derive"] }
tokio = { version = "1.38", features = ["full"] }
tokio-stream = "0.1.16"
rust-embed = "*"
serde = { version = "*", features = ["derive"] }
tokio = { version = "*", features = ["full"] }
tokio-stream = "*"
tokio-test = "*"
tower-http = { version = "0.6.1", features = ["fs", "trace"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
tower-http = { version = "*", features = ["fs", "trace"] }
tracing = "*"
tracing-subscriber = { version = "*", features = ["env-filter"] }
[features]
default = ["text", "binary"]

View file

@ -7,4 +7,5 @@ allow = [
"Unicode-3.0",
"Apache-2.0 WITH LLVM-exception",
"AGPL-3.0",
"NCSA",
]

View file

@ -1,6 +1,6 @@
use std::fmt::Display;
use rand::{distributions::Standard, prelude::Distribution};
use rand::{distr::StandardUniform, prelude::Distribution};
#[derive(Debug, PartialEq)]
pub enum Color {
@ -19,13 +19,13 @@ impl Display for Color {
}
}
impl Distribution<Color> for Standard {
impl Distribution<Color> for StandardUniform {
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> Color {
let index: u8 = rng.gen_range(0..3);
let index: u8 = rng.random_range(0..3);
match index {
0 => Color::W8(rng.gen()),
1 => Color::RGB24(rng.gen(), rng.gen(), rng.gen()),
2 => Color::RGBA32(rng.gen(), rng.gen(), rng.gen(), rng.gen()),
0 => Color::W8(rng.random()),
1 => Color::RGB24(rng.random(), rng.random(), rng.random()),
2 => Color::RGBA32(rng.random(), rng.random(), rng.random(), rng.random()),
_ => unreachable!(),
}
}

View file

@ -1,7 +1,7 @@
use axum::http::{self, HeaderMap, HeaderValue};
use axum_streams::StreamingFormat;
use futures::StreamExt;
use rand::{distributions::Standard, thread_rng, Rng};
use rand::{distr::StandardUniform, rng, Rng};
pub(crate) struct Multipart {
first: bool,
@ -11,8 +11,8 @@ pub(crate) struct Multipart {
impl Multipart {
pub(crate) fn new(boundary_length: usize, headers: HeaderMap) -> Self {
let boundary = thread_rng()
.sample_iter(Standard)
let boundary = rng()
.sample_iter(StandardUniform)
.filter(|c| match c {
32..127 | 128..=255 => true,
0..32 | 127 => false,

View file

@ -40,7 +40,7 @@ pub async fn serve(ctx: WebApiContext) -> AsyncResult<Never> {
let app = Router::new()
.route("/imgstream", get(image_stream))
.route("/stats", get(stats_stream))
.nest_service("/", assets)
.fallback_service(assets)
.with_state(ctx)
// logging middleware
.layer(