diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7164234..a421ed6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: CI on: push: - branches: [ main ] + branches: [main] pull_request: workflow_dispatch: @@ -14,15 +14,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - + - name: Install rust toolchain uses: dtolnay/rust-toolchain@stable - with: - components: rustfmt, clippy - + - name: Check formatting run: cargo fmt --all -- --check - + - name: Run clippy run: cargo clippy --all-targets --all-features -- -D warnings - \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 4fd5c4b..37b9bf1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1201,9 +1201,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.140" +version = "1.0.141" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +checksum = "30b9eff21ebe718216c6ec64e1d9ac57087aad11efc64e32002bce4a0d4c03d3" dependencies = [ "itoa", "memchr", diff --git a/Cargo.toml b/Cargo.toml index d09267f..659ef25 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ httparse = "1.10.1" iowrap = "0.2.1" log = "0.4.27" serde = { version = "1.0.219", features = ["derive"] } -serde_json = "1.0.140" +serde_json = "1.0.141" # We use `opt-level = "s"` as it significantly reduces binary size. [profile.release] diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 31578d3..7855e6d 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,3 @@ [toolchain] -channel = "stable" \ No newline at end of file +channel = "1.88.0" +components = ["rustfmt", "clippy"] diff --git a/src/main.rs b/src/main.rs index 60988db..ab8df7f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,7 @@ async fn main() -> std::io::Result<()> { let listen_port = config.server.listen_port; let worker_threads = config.server.worker_threads; - log::info!("Listening on {}:{}", listen_addr, listen_port,); + log::info!("Listening on {listen_addr}:{listen_port}",); HttpServer::new(move || { App::new() @@ -115,7 +115,7 @@ fn prepare_config(env: &environment::Environment) -> config::Config { Ok(config) => config, Err(err) => { - log::error!("Failed to build config: {}", err); + log::error!("Failed to build config: {err}"); process::exit(1) } } diff --git a/src/rce_engine/api/mod.rs b/src/rce_engine/api/mod.rs index b47aa58..2b28c9b 100644 --- a/src/rce_engine/api/mod.rs +++ b/src/rce_engine/api/mod.rs @@ -47,7 +47,7 @@ pub fn prepare_json_response( status_code: 500, body: ErrorBody { error: "response.serialize".to_string(), - message: format!("Failed to serialize response: {}", err), + message: format!("Failed to serialize response: {err}"), }, }), } diff --git a/src/rce_engine/api/version.rs b/src/rce_engine/api/version.rs index c478359..f88fa21 100644 --- a/src/rce_engine/api/version.rs +++ b/src/rce_engine/api/version.rs @@ -55,11 +55,11 @@ impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Error::UnixStream(err) => { - write!(f, "Unix socket failure: {}", err) + write!(f, "Unix socket failure: {err}") } Error::Version(err) => { - write!(f, "Failed to get docker version: {}", err) + write!(f, "Failed to get docker version: {err}") } } } diff --git a/src/rce_engine/docker.rs b/src/rce_engine/docker.rs index c465772..dfaa065 100644 --- a/src/rce_engine/docker.rs +++ b/src/rce_engine/docker.rs @@ -54,11 +54,11 @@ impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Error::PrepareRequest(err) => { - write!(f, "Failed to prepare request: {}", err) + write!(f, "Failed to prepare request: {err}") } Error::SendRequest(err) => { - write!(f, "Failed while sending request: {}", err) + write!(f, "Failed while sending request: {err}") } } } @@ -74,11 +74,11 @@ impl fmt::Display for PrepareRequestError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { PrepareRequestError::SerializeBody(err) => { - write!(f, "Failed to serialize request body: {}", err) + write!(f, "Failed to serialize request body: {err}") } PrepareRequestError::Request(err) => { - write!(f, "{}", err) + write!(f, "{err}") } } } @@ -167,7 +167,7 @@ pub fn create_container( pub fn start_container_request( container_id: &str, ) -> Result, http::Error> { - let url = format!("/containers/{}/start", container_id); + let url = format!("/containers/{container_id}/start"); http::Request::post(url) .header("Accept", "application/json") @@ -189,7 +189,7 @@ pub fn start_container( pub fn remove_container_request( container_id: &str, ) -> Result, http::Error> { - let url = format!("/containers/{}?v=1&force=1", container_id); + let url = format!("/containers/{container_id}?v=1&force=1"); http::Request::delete(url) .header("Accept", "application/json") @@ -211,10 +211,7 @@ pub fn remove_container( pub fn attach_container_request( container_id: &str, ) -> Result, http::Error> { - let url = format!( - "/containers/{}/attach?stream=1&stdout=1&stdin=1&stderr=1", - container_id - ); + let url = format!("/containers/{container_id}/attach?stream=1&stdout=1&stdin=1&stderr=1"); http::Request::post(url) .header("Host", "127.0.0.1") @@ -246,23 +243,23 @@ impl fmt::Display for StreamError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { StreamError::Read(err) => { - write!(f, "{}", err) + write!(f, "{err}") } StreamError::ReadStreamType(err) => { - write!(f, "Failed to read stream type: {}", err) + write!(f, "Failed to read stream type: {err}") } StreamError::UnknownStreamType(stream_type) => { - write!(f, "Unknown stream type: (type: {})", stream_type) + write!(f, "Unknown stream type: (type: {stream_type})") } StreamError::ReadStreamLength(err) => { - write!(f, "Failed to read stream length: {}", err) + write!(f, "Failed to read stream length: {err}") } StreamError::InvalidStreamLength(err) => { - write!(f, "Failed to parse stream length: {}", err) + write!(f, "Failed to parse stream length: {err}") } StreamError::MaxExecutionTime() => { @@ -270,7 +267,7 @@ impl fmt::Display for StreamError { } StreamError::MaxReadSize(max_size) => { - write!(f, "Max output size exceeded ({} bytes)", max_size) + write!(f, "Max output size exceeded ({max_size} bytes)") } } } diff --git a/src/rce_engine/environment.rs b/src/rce_engine/environment.rs index e6f3eca..d860437 100644 --- a/src/rce_engine/environment.rs +++ b/src/rce_engine/environment.rs @@ -52,12 +52,11 @@ pub enum Error { impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - Error::KeyNotFound(key) => write!(f, "Environment key not found: «{0}»", key), + Error::KeyNotFound(key) => write!(f, "Environment key not found: «{key}»"), Error::Parse { key, details } => write!( f, - "Failed to parse value for environment key: «{0}», details: {1}", - key, details + "Failed to parse value for environment key: «{key}», details: {details}" ), } } diff --git a/src/rce_engine/http_extra.rs b/src/rce_engine/http_extra.rs index 41c60c2..0efb8fa 100644 --- a/src/rce_engine/http_extra.rs +++ b/src/rce_engine/http_extra.rs @@ -37,33 +37,33 @@ impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Error::WriteRequest(err) => { - write!(f, "Failed to send request: {}", err) + write!(f, "Failed to send request: {err}") } Error::ReadResponse(err) => { - write!(f, "Failed read response: {}", err) + write!(f, "Failed read response: {err}") } Error::ParseResponseHead(err) => { - write!(f, "Failed parse response head: {}", err) + write!(f, "Failed parse response head: {err}") } Error::ReadChunkedBody(err) => { - write!(f, "Failed read to chunked response body: {}", err) + write!(f, "Failed read to chunked response body: {err}") } Error::ReadBody(err) => { - write!(f, "Failed read to response body: {}", err) + write!(f, "Failed read to response body: {err}") } Error::BadStatus(status_code, body) => { - let msg = String::from_utf8(body.to_vec()).unwrap_or(format!("{:?}", body)); + let msg = String::from_utf8(body.to_vec()).unwrap_or(format!("{body:?}")); - write!(f, "Unexpected status code {}: {}", status_code, msg) + write!(f, "Unexpected status code {status_code}: {msg}") } Error::DeserializeBody(err) => { - write!(f, "Failed deserialize response body: {}", err) + write!(f, "Failed deserialize response body: {err}") } } } @@ -134,19 +134,19 @@ impl fmt::Display for ReadChunkError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { ReadChunkError::ReadChunkLength(err) => { - write!(f, "Failed to read chunk length: {}", err) + write!(f, "Failed to read chunk length: {err}") } ReadChunkError::ParseChunkLength(err) => { - write!(f, "Failed parse chunk length: {}", err) + write!(f, "Failed parse chunk length: {err}") } ReadChunkError::ReadChunk(err) => { - write!(f, "Failed read chunk: {}", err) + write!(f, "Failed read chunk: {err}") } ReadChunkError::SkipLineFeed(err) => { - write!(f, "Failed read line feed at end of chunk: {}", err) + write!(f, "Failed read line feed at end of chunk: {err}") } } } @@ -251,10 +251,10 @@ pub fn format_request_headers(req: &Request) -> String { fn write_request_head(mut writer: W, req: &Request) -> Result<(), io::Error> { let request_line = format_request_line(req); - write!(writer, "{}\r\n", request_line)?; + write!(writer, "{request_line}\r\n")?; let headers = format_request_headers(req); - write!(writer, "{}\r\n\r\n", headers) + write!(writer, "{headers}\r\n\r\n") } fn write_request_body(mut writer: W, req: &Request) -> Result<(), io::Error> { @@ -291,7 +291,7 @@ impl fmt::Display for ParseError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { ParseError::Parse(err) => { - write!(f, "{}", err) + write!(f, "{err}") } ParseError::Empty() => { @@ -303,7 +303,7 @@ impl fmt::Display for ParseError { } ParseError::Response(err) => { - write!(f, "Invalid response: {}", err) + write!(f, "Invalid response: {err}") } } } @@ -348,11 +348,11 @@ impl fmt::Display for ResponseError { } ResponseError::HeaderName(err) => { - write!(f, "Invalid header name: {}", err) + write!(f, "Invalid header name: {err}") } ResponseError::HeaderValue(err) => { - write!(f, "Invalid header value: {}", err) + write!(f, "Invalid header value: {err}") } ResponseError::StatusCode() => { @@ -360,7 +360,7 @@ impl fmt::Display for ResponseError { } ResponseError::Builder(err) => { - write!(f, "Response builder error: {}", err) + write!(f, "Response builder error: {err}") } } } diff --git a/src/rce_engine/run.rs b/src/rce_engine/run.rs index db75ef2..9a129df 100644 --- a/src/rce_engine/run.rs +++ b/src/rce_engine/run.rs @@ -46,7 +46,7 @@ pub fn run( Ok(_) => {} Err(err) => { - log::error!("Failed to remove container: {}", err); + log::error!("Failed to remove container: {err}"); } } @@ -197,47 +197,43 @@ impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Error::UnixStream(err) => { - write!(f, "Unix socket failure: {}", err) + write!(f, "Unix socket failure: {err}") } Error::CreateContainer(err) => { - write!(f, "Failed to create container: {}", err) + write!(f, "Failed to create container: {err}") } Error::StartContainer(err) => { - write!(f, "Failed to start container: {}", err) + write!(f, "Failed to start container: {err}") } Error::AttachContainer(err) => { - write!(f, "Failed to attach to container: {}", err) + write!(f, "Failed to attach to container: {err}") } Error::SerializePayload(err) => { - write!(f, "Failed to send payload to stream: {}", err) + write!(f, "Failed to send payload to stream: {err}") } Error::ReadStream(err) => { - write!(f, "Failed while reading stream: {}", err) + write!(f, "Failed while reading stream: {err}") } Error::StreamStdinUnexpected(bytes) => { - let msg = String::from_utf8(bytes.to_vec()).unwrap_or(format!("{:?}", bytes)); + let msg = String::from_utf8(bytes.to_vec()).unwrap_or(format!("{bytes:?}")); - write!(f, "Code runner returned unexpected stdin data: {}", msg) + write!(f, "Code runner returned unexpected stdin data: {msg}") } Error::StreamStderr(bytes) => { - let msg = String::from_utf8(bytes.to_vec()).unwrap_or(format!("{:?}", bytes)); + let msg = String::from_utf8(bytes.to_vec()).unwrap_or(format!("{bytes:?}")); - write!(f, "Code runner failed with the following message: {}", msg) + write!(f, "Code runner failed with the following message: {msg}") } Error::StreamStdoutDecode(err) => { - write!( - f, - "Failed to decode json returned from code runner: {}", - err - ) + write!(f, "Failed to decode json returned from code runner: {err}") } } } diff --git a/src/rce_engine/unix_stream.rs b/src/rce_engine/unix_stream.rs index 1a389cb..d2816da 100644 --- a/src/rce_engine/unix_stream.rs +++ b/src/rce_engine/unix_stream.rs @@ -53,11 +53,11 @@ impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Error::Connect(err) => { - write!(f, "Failed to connect to docker unix socket: {}", err) + write!(f, "Failed to connect to docker unix socket: {err}") } Error::SetStreamTimeout(err) => { - write!(f, "Failed set timeout on unix socket: {}", err) + write!(f, "Failed set timeout on unix socket: {err}") } } }