Update random (#82)
This commit is contained in:
commit
3525f4c40e
6 changed files with 326 additions and 230 deletions
499
Cargo.lock
generated
499
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
36
Cargo.toml
36
Cargo.toml
|
|
@ -5,26 +5,26 @@ edition = "2021"
|
||||||
license = "AGPL-3.0"
|
license = "AGPL-3.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-trait = "0.1.83"
|
async-trait = "*"
|
||||||
atoi_radix10 = { version = "0.0.1", optional = true }
|
atoi_radix10 = { version = "*", optional = true }
|
||||||
axum = { version = "0.7.7", features = ["ws"] }
|
axum = { version = "*", features = ["ws"] }
|
||||||
axum-embed = "0.1.0"
|
axum-embed = "*"
|
||||||
axum-extra = { version = "0.9.4", features = ["typed-header"] }
|
axum-extra = { version = "*", features = ["typed-header"] }
|
||||||
axum-streams = "0.19.0"
|
axum-streams = "*"
|
||||||
bytes = "1.6.0"
|
bytes = "*"
|
||||||
chrono = "0.4.38"
|
chrono = "*"
|
||||||
futures = "0.3.31"
|
futures = "*"
|
||||||
headers = "0.4.0"
|
headers = "*"
|
||||||
image = "0.25.2"
|
image = "*"
|
||||||
rand = "*"
|
rand = "*"
|
||||||
rust-embed = "8.5.0"
|
rust-embed = "*"
|
||||||
serde = { version = "1.0.210", features = ["derive"] }
|
serde = { version = "*", features = ["derive"] }
|
||||||
tokio = { version = "1.38", features = ["full"] }
|
tokio = { version = "*", features = ["full"] }
|
||||||
tokio-stream = "0.1.16"
|
tokio-stream = "*"
|
||||||
tokio-test = "*"
|
tokio-test = "*"
|
||||||
tower-http = { version = "0.6.1", features = ["fs", "trace"] }
|
tower-http = { version = "*", features = ["fs", "trace"] }
|
||||||
tracing = "0.1.40"
|
tracing = "*"
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
tracing-subscriber = { version = "*", features = ["env-filter"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["text", "binary"]
|
default = ["text", "binary"]
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,5 @@ allow = [
|
||||||
"Unicode-3.0",
|
"Unicode-3.0",
|
||||||
"Apache-2.0 WITH LLVM-exception",
|
"Apache-2.0 WITH LLVM-exception",
|
||||||
"AGPL-3.0",
|
"AGPL-3.0",
|
||||||
|
"NCSA",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
12
src/color.rs
12
src/color.rs
|
|
@ -1,6 +1,6 @@
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
use rand::{distributions::Standard, prelude::Distribution};
|
use rand::{distr::StandardUniform, prelude::Distribution};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum Color {
|
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 {
|
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 {
|
match index {
|
||||||
0 => Color::W8(rng.gen()),
|
0 => Color::W8(rng.random()),
|
||||||
1 => Color::RGB24(rng.gen(), rng.gen(), rng.gen()),
|
1 => Color::RGB24(rng.random(), rng.random(), rng.random()),
|
||||||
2 => Color::RGBA32(rng.gen(), rng.gen(), rng.gen(), rng.gen()),
|
2 => Color::RGBA32(rng.random(), rng.random(), rng.random(), rng.random()),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use axum::http::{self, HeaderMap, HeaderValue};
|
use axum::http::{self, HeaderMap, HeaderValue};
|
||||||
use axum_streams::StreamingFormat;
|
use axum_streams::StreamingFormat;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use rand::{distributions::Standard, thread_rng, Rng};
|
use rand::{distr::StandardUniform, rng, Rng};
|
||||||
|
|
||||||
pub(crate) struct Multipart {
|
pub(crate) struct Multipart {
|
||||||
first: bool,
|
first: bool,
|
||||||
|
|
@ -11,8 +11,8 @@ pub(crate) struct Multipart {
|
||||||
|
|
||||||
impl Multipart {
|
impl Multipart {
|
||||||
pub(crate) fn new(boundary_length: usize, headers: HeaderMap) -> Self {
|
pub(crate) fn new(boundary_length: usize, headers: HeaderMap) -> Self {
|
||||||
let boundary = thread_rng()
|
let boundary = rng()
|
||||||
.sample_iter(Standard)
|
.sample_iter(StandardUniform)
|
||||||
.filter(|c| match c {
|
.filter(|c| match c {
|
||||||
32..127 | 128..=255 => true,
|
32..127 | 128..=255 => true,
|
||||||
0..32 | 127 => false,
|
0..32 | 127 => false,
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ pub async fn serve(ctx: WebApiContext) -> AsyncResult<Never> {
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/imgstream", get(image_stream))
|
.route("/imgstream", get(image_stream))
|
||||||
.route("/stats", get(stats_stream))
|
.route("/stats", get(stats_stream))
|
||||||
.nest_service("/", assets)
|
.fallback_service(assets)
|
||||||
.with_state(ctx)
|
.with_state(ctx)
|
||||||
// logging middleware
|
// logging middleware
|
||||||
.layer(
|
.layer(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue