Skip to content

Commit e2c9c86

Browse files
authored
build(toolchain): update to rust 2024 (#731)
1 parent 4b76691 commit e2c9c86

File tree

128 files changed

+687
-670
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+687
-670
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ env:
1616
REGISTRY: "ghcr.io"
1717
IMAGE_NAME: "clash-rs"
1818
RUST_LOG: "clash=TRACE"
19-
RUST_TOOLCHAIN: "nightly-2024-12-20"
19+
RUST_TOOLCHAIN: "nightly"
2020

2121
# Arm builder https://github.blog/changelog/2024-09-03-github-actions-arm64-linux-and-windows-runners-are-now-generally-available/
2222
jobs:

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ members = [
1212
[workspace.package]
1313
version = "0.7.5"
1414
repository = "https://github.com/Watfaq/clash-rs.git"
15-
edition = "2021"
15+
edition = "2024"
1616

1717
[profile.release]
1818
opt-level = "s"

clash/src/main.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ fn main() {
8181

8282
if !Path::new(&file).exists() {
8383
let default_config = "port: 7890";
84-
let mut config_file = if let Ok(config_file) = std::fs::File::create(&file) {
85-
config_file
86-
} else {
87-
eprintln!("default profile cannot be created: {}", file);
88-
exit(1);
84+
let mut config_file = match std::fs::File::create(&file) {
85+
Ok(config_file) => config_file,
86+
_ => {
87+
eprintln!("default profile cannot be created: {}", file);
88+
exit(1);
89+
}
8990
};
9091

9192
if config_file.write_all(default_config.as_bytes()).is_err() {

clash_ffi/src/lib.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,47 @@
1-
use clash_lib::{shutdown, start_scaffold, Config, Options, TokioRuntime};
1+
use clash_lib::{Config, Options, TokioRuntime, shutdown, start_scaffold};
22
use std::{
33
ffi::{CStr, CString},
44
os::raw::{c_char, c_int},
55
};
66

77
/// # Safety
88
/// This function is unsafe because it dereferences raw pointers.
9-
#[no_mangle]
9+
#[unsafe(no_mangle)]
1010
pub unsafe extern "C" fn clash_start(
1111
config: *const c_char,
1212
log: *const c_char,
1313
cwd: *const c_char,
1414
multithread: c_int,
1515
) -> *mut c_char {
16-
let config_str = CStr::from_ptr(config)
17-
.to_str()
18-
.unwrap_or_default()
19-
.to_string();
20-
let log_str = CStr::from_ptr(log).to_str().unwrap_or_default().to_string();
21-
let cwd_str = CStr::from_ptr(cwd).to_str().unwrap_or_default().to_string();
16+
unsafe {
17+
let config_str = CStr::from_ptr(config)
18+
.to_str()
19+
.unwrap_or_default()
20+
.to_string();
21+
let log_str = CStr::from_ptr(log).to_str().unwrap_or_default().to_string();
22+
let cwd_str = CStr::from_ptr(cwd).to_str().unwrap_or_default().to_string();
2223

23-
let rt = if multithread != 0 {
24-
Some(TokioRuntime::MultiThread)
25-
} else {
26-
Some(TokioRuntime::SingleThread)
27-
};
24+
let rt = if multithread != 0 {
25+
Some(TokioRuntime::MultiThread)
26+
} else {
27+
Some(TokioRuntime::SingleThread)
28+
};
2829

29-
let options = Options {
30-
config: Config::Str(config_str),
31-
cwd: Some(cwd_str),
32-
rt,
33-
log_file: Some(log_str),
34-
};
30+
let options = Options {
31+
config: Config::Str(config_str),
32+
cwd: Some(cwd_str),
33+
rt,
34+
log_file: Some(log_str),
35+
};
3536

36-
match start_scaffold(options) {
37-
Ok(_) => CString::new("").unwrap().into_raw(),
38-
Err(e) => CString::new(format!("Error: {}", e)).unwrap().into_raw(),
37+
match start_scaffold(options) {
38+
Ok(_) => CString::new("").unwrap().into_raw(),
39+
Err(e) => CString::new(format!("Error: {}", e)).unwrap().into_raw(),
40+
}
3941
}
4042
}
4143

42-
#[no_mangle]
44+
#[unsafe(no_mangle)]
4345
pub extern "C" fn clash_shutdown() -> c_int {
4446
if shutdown() {
4547
1 // Success
@@ -50,7 +52,7 @@ pub extern "C" fn clash_shutdown() -> c_int {
5052

5153
/// # Safety
5254
/// This function is unsafe because it dereferences raw pointers.
53-
#[no_mangle]
55+
#[unsafe(no_mangle)]
5456
#[allow(unused_must_use)]
5557
pub unsafe extern "C" fn clash_free_string(s: *mut c_char) {
5658
if s.is_null() {

clash_lib/src/app/api/handlers/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::{path::PathBuf, sync::Arc};
22

33
use axum::{
4+
Json, Router,
45
extract::{Query, State},
56
response::IntoResponse,
67
routing::get,
7-
Json, Router,
88
};
99

1010
use http::StatusCode;
@@ -13,14 +13,14 @@ use tokio::sync::Mutex;
1313
use tracing::warn;
1414

1515
use crate::{
16+
GlobalState,
1617
app::{
1718
api::AppState,
1819
dispatcher,
1920
dns::ThreadSafeDNSResolver,
2021
inbound::manager::{Ports, ThreadSafeInboundManager},
2122
},
2223
config::{def, internal::config::BindAddress},
23-
GlobalState,
2424
};
2525

2626
#[derive(Clone)]

clash_lib/src/app/api/handlers/connection.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
use std::sync::Arc;
22

33
use axum::{
4+
Json, Router,
45
body::Body,
56
extract::{
6-
ws::Message, FromRequest, Path, Query, Request, State, WebSocketUpgrade,
7+
FromRequest, Path, Query, Request, State, WebSocketUpgrade, ws::Message,
78
},
89
response::IntoResponse,
910
routing::{delete, get},
10-
Json, Router,
1111
};
1212
use http::HeaderMap;
1313
use serde::Deserialize;
1414
use tracing::{debug, warn};
1515

1616
use crate::app::{
17-
api::{handlers::utils::is_request_websocket, AppState},
17+
api::{AppState, handlers::utils::is_request_websocket},
1818
dispatcher::StatisticsManager,
1919
};
2020

clash_lib/src/app/api/handlers/dns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::sync::Arc;
22

33
use axum::{
4+
Json, Router,
45
extract::{Query, State},
56
response::IntoResponse,
67
routing::get,
7-
Json, Router,
88
};
99
use hickory_proto::{op::Message, rr::RecordType};
1010
use http::StatusCode;

clash_lib/src/app/api/handlers/log.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{net::SocketAddr, sync::Arc};
22

33
use axum::{
4-
extract::{ws::Message, ConnectInfo, State, WebSocketUpgrade},
4+
extract::{ConnectInfo, State, WebSocketUpgrade, ws::Message},
55
response::IntoResponse,
66
};
77

clash_lib/src/app/api/handlers/memory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::sync::Arc;
22

33
use axum::{
4+
Json,
45
body::Body,
5-
extract::{ws::Message, FromRequest, Query, Request, State, WebSocketUpgrade},
6+
extract::{FromRequest, Query, Request, State, WebSocketUpgrade, ws::Message},
67
response::IntoResponse,
7-
Json,
88
};
99
use http::HeaderMap;
1010
use serde::{Deserialize, Serialize};

clash_lib/src/app/api/handlers/provider.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::{collections::HashMap, sync::Arc, time::Duration};
22

33
use axum::{
4+
Extension, Router,
45
extract::{Path, Query, State},
56
http::{Request, StatusCode},
67
middleware::{self, Next},
78
response::{IntoResponse, Response},
89
routing::get,
9-
Extension, Router,
1010
};
1111
use serde::Deserialize;
1212

@@ -79,15 +79,16 @@ async fn find_proxy_provider_by_name(
7979
next: Next,
8080
) -> Response {
8181
let outbound_manager = state.outbound_manager.clone();
82-
if let Some(provider) = outbound_manager.get_proxy_provider(&name) {
83-
req.extensions_mut().insert(provider);
84-
next.run(req).await
85-
} else {
86-
(
82+
match outbound_manager.get_proxy_provider(&name) {
83+
Some(provider) => {
84+
req.extensions_mut().insert(provider);
85+
next.run(req).await
86+
}
87+
_ => (
8788
StatusCode::NOT_FOUND,
8889
format!("proxy provider {} not found", name),
8990
)
90-
.into_response()
91+
.into_response(),
9192
}
9293
}
9394

0 commit comments

Comments
 (0)