Skip to content

Commit 7301967

Browse files
author
share121
committed
feat: 逐步移除 std
1 parent e57c385 commit 7301967

File tree

9 files changed

+294
-193
lines changed

9 files changed

+294
-193
lines changed

.github/workflows/test.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ jobs:
3333
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
3434
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
3535
36-
- name: Clippy
37-
run: cargo clippy --all-targets --all-features --verbose -- -Dwarnings
38-
3936
- name: Test
40-
run: cargo test --all-targets --all-features --verbose
37+
run: cargo test --all --verbose
38+
39+
- name: Build
40+
run: cargo build --all --verbose
41+
42+
- name: Clippy
43+
run: cargo clippy --all --verbose -- -Dwarnings
4144

4245
check-minimal:
4346
name: Check minimal versions

Cargo.lock

Lines changed: 18 additions & 92 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ keywords = ["downloader", "parallel", "thread", "concurrency", "performance"]
1414
categories = ["network-programming", "concurrency"]
1515

1616
[dependencies]
17-
tokio = { version = "1.47.0", features = [
17+
tokio = { version = "1.47.1", features = [
1818
"fs",
1919
"macros",
2020
"sync",
@@ -25,7 +25,7 @@ tokio = { version = "1.47.0", features = [
2525
kanal = "0.1.1"
2626
bytes = "1.10.1"
2727
futures = "0.3.31"
28-
fast-steal = "5.0.2"
28+
fast-steal = "5.1.0"
2929
memmap2 = { version = "0.9.7", optional = true }
3030
reqwest = { version = "0.12.22", features = [
3131
"gzip",

src/core/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
macro_rules! check_running {
22
($id:expr, $running:expr, $tx:expr) => {
3-
if !$running.load(std::sync::atomic::Ordering::Relaxed) {
3+
if !$running.load(core::sync::atomic::Ordering::Relaxed) {
44
$tx.send($crate::Event::Abort($id)).await.unwrap();
55
return;
66
}

src/core/mock.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
extern crate alloc;
12
use crate::{ProgressEntry, RandReader, RandWriter, SeqReader, SeqWriter};
3+
use alloc::sync::Arc;
24
use bytes::Bytes;
35
use futures::{TryStream, lock::Mutex, stream};
4-
use std::sync::Arc;
56

67
pub fn build_mock_data(size: usize) -> Vec<u8> {
78
(0..size).map(|i| (i % 256) as u8).collect()
89
}
910

1011
#[derive(Clone)]
11-
pub struct MockRandReader(pub Arc<Vec<u8>>);
12+
pub struct MockRandReader(pub Arc<[u8]>);
1213
impl MockRandReader {
13-
pub fn new(data: Vec<u8>) -> Self {
14-
Self(Arc::new(data))
14+
pub fn new(data: &[u8]) -> Self {
15+
Self(Arc::from(data))
1516
}
1617
}
1718
impl RandReader for MockRandReader {
@@ -41,13 +42,13 @@ impl SeqReader for MockSeqReader {
4142
#[derive(Clone)]
4243
pub struct MockRandWriter {
4344
pub receive: Arc<Mutex<Vec<u8>>>,
44-
pub result: Arc<Vec<u8>>,
45+
pub result: Arc<[u8]>,
4546
}
4647
impl MockRandWriter {
47-
pub fn new(result: Vec<u8>) -> Self {
48+
pub fn new(result: &[u8]) -> Self {
4849
Self {
4950
receive: Arc::new(Mutex::new(vec![0; result.len()])),
50-
result: Arc::new(result),
51+
result: Arc::from(result),
5152
}
5253
}
5354
pub async fn assert(&self) {
@@ -67,12 +68,12 @@ impl RandWriter for MockRandWriter {
6768
#[derive(Clone)]
6869
pub struct MockSeqWriter {
6970
pub receive: Arc<Mutex<Vec<u8>>>,
70-
pub result: Arc<Vec<u8>>,
71+
pub result: Arc<[u8]>,
7172
}
7273
impl MockSeqWriter {
73-
pub fn new(result: Vec<u8>) -> Self {
74+
pub fn new(result: &[u8]) -> Self {
7475
Self {
75-
result: Arc::new(result),
76+
result: Arc::from(result),
7677
receive: Arc::new(Mutex::new(vec![])),
7778
}
7879
}

src/core/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
extern crate alloc;
12
use crate::Event;
3+
use alloc::sync::Arc;
24
use core::{
35
fmt::Debug,
46
sync::atomic::{AtomicBool, Ordering},
57
};
68
use futures::lock::Mutex;
79
use kanal::AsyncReceiver;
8-
use std::sync::Arc;
910
use tokio::task::{JoinError, JoinHandle};
1011

1112
mod macros;
1213
#[cfg(test)]
13-
mod mock;
14+
pub mod mock;
1415
pub mod multi;
1516
pub mod single;
1617

0 commit comments

Comments
 (0)