Skip to content
This repository was archived by the owner on Oct 23, 2022. It is now read-only.

Commit 2f39590

Browse files
committed
Use core crate where is applicable within unixfs
1 parent 34f53fb commit 2f39590

File tree

19 files changed

+57
-55
lines changed

19 files changed

+57
-55
lines changed

src/unixfs/cat.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use async_stream::stream;
33
use cid::Cid;
44
use futures::stream::Stream;
55
use ipfs_unixfs::file::{visit::IdleFileVisit, FileReadFailed};
6-
use std::borrow::Borrow;
7-
use std::fmt;
8-
use std::ops::Range;
6+
use core::borrow::Borrow;
7+
use core::fmt;
8+
use core::ops::Range;
99

1010
/// IPFS cat operation, producing a stream of file bytes. This is generic over the different kinds
1111
/// of ways to own an `Ipfs` value in order to support both operating with borrowed `Ipfs` value

unixfs/src/dagpb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
///! follows from the inseparability of dag-pb and UnixFS.
33
use crate::pb::PBNode;
44
use std::borrow::Cow;
5-
use std::convert::TryFrom;
5+
use core::convert::TryFrom;
66

77
/// Extracts the PBNode::Data field from the block as it appears on the block.
88
pub fn node_data(block: &[u8]) -> Result<Option<&[u8]>, quick_protobuf::Error> {

unixfs/src/dir.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::pb::{FlatUnixFs, PBLink, PBNode, ParsingFailed, UnixFsType};
22
use crate::{InvalidCidInLink, UnexpectedNodeType};
33
use cid::Cid;
4-
use std::convert::TryFrom;
5-
use std::fmt;
4+
use core::convert::TryFrom;
5+
use core::fmt;
66

77
mod sharded_lookup;
88
pub use sharded_lookup::{Cache, LookupError, ShardError, ShardedLookup};
@@ -217,7 +217,7 @@ mod tests {
217217
use crate::test_support::FakeBlockstore;
218218
use cid::Cid;
219219
use hex_literal::hex;
220-
use std::convert::TryFrom;
220+
use core::convert::TryFrom;
221221

222222
#[test]
223223
fn resolve_paths_from_plain_dagpb() {

unixfs/src/dir/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use cid::Cid;
2-
use std::fmt;
2+
use core::fmt;
33

44
mod dir_builder;
55
use dir_builder::DirBuilder;

unixfs/src/dir/builder/buffered.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ mod tests {
189189
super::OwnedTreeNode, BufferingTreeBuilder, Metadata, TreeBuildingFailed, TreeOptions,
190190
};
191191
use cid::Cid;
192-
use std::convert::TryFrom;
192+
use core::convert::TryFrom;
193193

194194
#[test]
195195
fn some_directories() {
@@ -398,12 +398,12 @@ mod tests {
398398

399399
fn verify_results(
400400
mut expected: Vec<(
401-
impl AsRef<str> + std::fmt::Debug,
402-
impl AsRef<str> + std::fmt::Debug,
401+
impl AsRef<str> + core::fmt::Debug,
402+
impl AsRef<str> + core::fmt::Debug,
403403
)>,
404404
mut actual: Vec<(String, Cid, Box<[u8]>)>,
405405
) {
406-
use std::fmt;
406+
use core::fmt;
407407

408408
struct Hex<'a>(&'a [u8]);
409409

unixfs/src/dir/builder/iter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::{
33
};
44
use cid::Cid;
55
use std::collections::HashMap;
6-
use std::fmt;
6+
use core::fmt;
77

88
/// Constructs the directory nodes required for a tree.
99
///
@@ -132,7 +132,7 @@ impl PostOrderIterator {
132132
needed_zeroes -= zeroes.len();
133133
}
134134

135-
buffer.extend(std::iter::repeat(0).take(needed_zeroes));
135+
buffer.extend(core::iter::repeat(0).take(needed_zeroes));
136136
}
137137

138138
let mut writer = Writer::new(BytesWriter::new(&mut buffer[..]));

unixfs/src/dir/directory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::pb::FlatUnixFs;
2-
use std::fmt;
2+
use core::fmt;
33

44
/// Ensures the directory looks like something we actually support.
55
pub(crate) fn check_directory_supported(

unixfs/src/dir/sharded_lookup.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::{InvalidCidInLink, UnexpectedNodeType};
44
use cid::Cid;
55
use std::borrow::Cow;
66
use std::collections::VecDeque;
7-
use std::convert::TryFrom;
8-
use std::fmt;
7+
use core::convert::TryFrom;
8+
use core::fmt;
99

1010
/// A cache of data structures used while traversing. Reduces allocations when walking over multiple
1111
/// path segments.
@@ -148,7 +148,7 @@ impl<'needle> ShardedLookup<'needle> {
148148
} else if hamt.data.filesize.is_some() || !hamt.data.blocksizes.is_empty() {
149149
Err(ShardError::UnexpectedProperties {
150150
filesize: hamt.data.filesize,
151-
blocksizes: std::mem::take(&mut hamt.data.blocksizes),
151+
blocksizes: core::mem::take(&mut hamt.data.blocksizes),
152152
})
153153
} else {
154154
Ok(())
@@ -338,7 +338,7 @@ mod tests {
338338
use super::{LookupError, MaybeResolved, ShardError, ShardedLookup};
339339
use crate::pb::FlatUnixFs;
340340
use hex_literal::hex;
341-
use std::convert::TryFrom;
341+
use core::convert::TryFrom;
342342

343343
// a directory from some linux kernel tree import: linux-5.5-rc5/tools/testing/selftests/rcutorture/
344344
const DIR: &[u8] = &hex!("122e0a2212204baf5104fe53d495223f8e2ba95375a31fda6b18e926cb54edd61f30b5f1de6512053641646f6318b535122c0a221220fd9f545068048e647d5d0b275ed171596e0c1c04b8fed09dc13bee7607e75bc7120242391883c00312330a2212208a4a68f6b88594ce373419586c12d24bde2d519ab636b1d2dcc986eb6265b7a3120a43444d616b6566696c65189601122f0a2212201ededc99d23a7ef43a8f17e6dd8b89934993245ef39e18936a37e412e536ed681205463562696e18c5ad030a280805121f200000000020000200000000000000000004000000000000000000000000002822308002");

unixfs/src/file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use crate::pb::ParsingFailed;
66
use crate::{InvalidCidInLink, Metadata, UnexpectedNodeType};
77
use std::borrow::Cow;
8-
use std::fmt;
8+
use core::fmt;
99

1010
/// Low level UnixFS file descriptor reader support.
1111
mod reader;

unixfs/src/file/adder.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use cid::Cid;
33
use crate::pb::{FlatUnixFs, PBLink, UnixFs, UnixFsType};
44
use quick_protobuf::{MessageWrite, Writer};
55
use std::borrow::Cow;
6-
use std::fmt;
6+
use core::fmt;
77

88
use sha2::{Digest, Sha256};
99

10-
/// File tree builder. Implements [`std::default::Default`] which tracks the recent defaults.
10+
/// File tree builder. Implements [`core::default::Default`] which tracks the recent defaults.
1111
///
1212
/// Custom file tree builder can be created with [`FileAdder::builder()`] and configuring the
1313
/// chunker and collector.
@@ -327,7 +327,7 @@ pub enum Chunker {
327327
Size(usize),
328328
}
329329

330-
impl std::default::Default for Chunker {
330+
impl core::default::Default for Chunker {
331331
/// Returns a default chunker which matches go-ipfs 0.6
332332
fn default() -> Self {
333333
Chunker::Size(256 * 1024)
@@ -367,7 +367,7 @@ pub enum Collector {
367367
Balanced(BalancedCollector),
368368
}
369369

370-
impl std::default::Default for Collector {
370+
impl core::default::Default for Collector {
371371
fn default() -> Self {
372372
Collector::Balanced(Default::default())
373373
}
@@ -404,7 +404,7 @@ impl fmt::Debug for BalancedCollector {
404404
}
405405
}
406406

407-
impl std::default::Default for BalancedCollector {
407+
impl core::default::Default for BalancedCollector {
408408
/// Returns a default collector which matches go-ipfs 0.6
409409
///
410410
/// The origin for 174 is not described in the the [specs], but has likely to do something
@@ -487,8 +487,8 @@ impl BalancedCollector {
487487

488488
let mut ret = Vec::new();
489489

490-
let mut reused_links = std::mem::take(&mut self.reused_links);
491-
let mut reused_blocksizes = std::mem::take(&mut self.reused_blocksizes);
490+
let mut reused_links = core::mem::take(&mut self.reused_links);
491+
let mut reused_blocksizes = core::mem::take(&mut self.reused_blocksizes);
492492

493493
if let Some(need) = self.branching_factor.checked_sub(reused_links.capacity()) {
494494
reused_links.reserve(need);
@@ -647,7 +647,7 @@ mod tests {
647647
use crate::test_support::FakeBlockstore;
648648
use cid::Cid;
649649
use hex_literal::hex;
650-
use std::convert::TryFrom;
650+
use core::convert::TryFrom;
651651

652652
#[test]
653653
fn test_size_chunker() {

unixfs/src/file/reader.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::pb::{FlatUnixFs, PBLink, RangeLinks, UnixFsType};
2-
use std::convert::TryFrom;
3-
use std::fmt;
4-
use std::ops::Range;
2+
use core::convert::TryFrom;
3+
use core::fmt;
4+
use core::ops::Range;
55

66
use crate::file::{FileError, FileReadFailed, Metadata, UnwrapBorrowedExt};
77

unixfs/src/file/visit.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use cid::Cid;
2-
use std::convert::TryFrom;
3-
use std::ops::Range;
2+
use core::convert::TryFrom;
3+
use core::ops::Range;
44

55
use crate::file::reader::{FileContent, FileReader, Traversal};
66
use crate::file::{FileReadFailed, Metadata};
@@ -225,7 +225,7 @@ fn to_pending(
225225
/// Returns true if the blocks byte offsets are interesting for our target range, false otherwise.
226226
/// If there is no target, all blocks are of interest.
227227
fn block_is_in_target_range(block: &Range<u64>, target: Option<&Range<u64>>) -> bool {
228-
use std::cmp::{max, min};
228+
use core::cmp::{max, min};
229229

230230
if let Some(target) = target {
231231
max(block.start, target.start) <= min(block.end, target.end)
@@ -249,7 +249,7 @@ fn maybe_target_slice<'a>(
249249
}
250250

251251
fn target_slice<'a>(content: &'a [u8], block: &Range<u64>, target: &Range<u64>) -> &'a [u8] {
252-
use std::cmp::min;
252+
use core::cmp::min;
253253

254254
if !block_is_in_target_range(block, Some(target)) {
255255
// defaulting to empty slice is good, and similar to the "cat" HTTP API operation.
@@ -284,7 +284,7 @@ mod tests {
284284
#[test]
285285
#[allow(clippy::type_complexity)]
286286
fn slice_for_target() {
287-
use std::ops::Range;
287+
use core::ops::Range;
288288

289289
// turns out these examples are not easy to determine at all
290290
// writing out the type here avoids &b""[..] inside the array.

unixfs/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! `ipfs_unixfs::resolve` should be used.
1010
1111
use std::borrow::Cow;
12-
use std::fmt;
12+
use core::fmt;
1313

1414
/// File support.
1515
pub mod file;
@@ -148,7 +148,7 @@ impl Metadata {
148148

149149
/// Returns the raw timestamp of last modification time, if specified.
150150
///
151-
/// The timestamp is `(seconds, nanos)` - similar to `std::time::Duration`, with the exception of
151+
/// The timestamp is `(seconds, nanos)` - similar to `core::time::Duration`, with the exception of
152152
/// allowing seconds to be negative. The seconds are calculated from `1970-01-01 00:00:00` or
153153
/// the common "unix epoch".
154154
pub fn mtime(&self) -> Option<(i64, u32)> {

unixfs/src/pb.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use quick_protobuf::{errors::Result as ProtobufResult, Writer, WriterBackend};
22
use std::borrow::Cow;
3-
use std::convert::TryFrom;
4-
use std::fmt;
5-
use std::ops::Range;
3+
use core::convert::TryFrom;
4+
use core::fmt;
5+
use core::ops::Range;
66

77
pub(crate) mod merkledag;
88
pub(crate) use merkledag::PBLink;
@@ -198,11 +198,10 @@ where
198198

199199
#[cfg(test)]
200200
mod test {
201-
202201
use super::{FlatUnixFs, PBNode, UnixFs, UnixFsType};
203202
use hex_literal::hex;
204203
use std::borrow::Cow;
205-
use std::convert::TryFrom;
204+
use core::convert::TryFrom;
206205

207206
#[test]
208207
fn parse_content() {

unixfs/src/pb/merkledag.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ use super::*;
1010
use quick_protobuf::sizeofs::*;
1111
use quick_protobuf::{BytesReader, MessageRead, MessageWrite, Result, Writer, WriterBackend};
1212
use std::borrow::Cow;
13-
use std::convert::TryFrom;
13+
use core::convert::TryFrom;
1414
use std::io::Write;
15-
use std::ops::Deref;
16-
use std::ops::DerefMut;
15+
use core::ops::Deref;
16+
use core::ops::DerefMut;
17+
1718
#[derive(Debug, Default, PartialEq, Clone)]
1819
pub struct PBLink<'a> {
1920
pub Hash: Option<Cow<'a, [u8]>>,

unixfs/src/pb/unixfs.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
#![allow(unknown_lints)]
77
#![allow(clippy::all)]
88
#![cfg_attr(rustfmt, rustfmt_skip)]
9+
910
use super::*;
1011
use quick_protobuf::sizeofs::*;
1112
use quick_protobuf::{BytesReader, MessageRead, MessageWrite, Result, Writer, WriterBackend};
1213
use std::borrow::Cow;
13-
use std::convert::TryFrom;
14+
use core::convert::TryFrom;
1415
use std::io::Write;
15-
use std::ops::Deref;
16-
use std::ops::DerefMut;
16+
use core::ops::Deref;
17+
use core::ops::DerefMut;
18+
1719
#[derive(Debug, Default, PartialEq, Clone)]
1820
pub struct Data<'a> {
1921
pub Type: mod_Data::DataType,

unixfs/src/symlink.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ mod tests {
3434
use super::serialize_symlink_block;
3535
use cid::Cid;
3636
use sha2::{Digest, Sha256};
37-
use std::convert::TryFrom;
37+
use core::convert::TryFrom;
3838

3939
#[test]
4040
fn simple_symlink() {
@@ -172,7 +172,7 @@ mod tests {
172172
ContinuedWalk::Symlink(link_name, _cid, path, _metadata) => {
173173
actual.push(Entry::Symlink(
174174
path.into(),
175-
std::str::from_utf8(link_name).unwrap().to_owned(),
175+
core::str::from_utf8(link_name).unwrap().to_owned(),
176176
));
177177
}
178178
};

unixfs/src/test_support.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use cid::Cid;
22
use hex_literal::hex;
33
use std::collections::HashMap;
4-
use std::convert::TryFrom;
4+
use core::convert::TryFrom;
55

66
#[derive(Default)]
77
pub struct FakeBlockstore {

unixfs/src/walk.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::{InvalidCidInLink, Metadata, UnexpectedNodeType};
66
use cid::Cid;
77
use either::Either;
88
use std::borrow::Cow;
9-
use std::convert::TryFrom;
10-
use std::fmt;
9+
use core::convert::TryFrom;
10+
use core::fmt;
1111
use std::path::{Path, PathBuf};
1212

1313
/// `Walker` helps with walking a UnixFS tree, including all of the content and files. It is
@@ -772,7 +772,7 @@ mod tests {
772772
}
773773

774774
fn sharded_dir_scenario(root_name: &str) {
775-
use std::fmt::Write;
775+
use core::fmt::Write;
776776

777777
// the hamt sharded directory is such that the root only has buckets so all of the actual files
778778
// are at second level buckets, each bucket should have 2 files. the actual files, in fact, constitute a single empty

0 commit comments

Comments
 (0)