Skip to content

Commit ca67287

Browse files
committed
Make all diskio functions and structs crate-private
Make some fields private
1 parent 5e43c1e commit ca67287

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

src/diskio/immediate.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::{
1414
use super::{CompletedIo, Executor, FileBuffer, Item};
1515

1616
#[derive(Debug)]
17-
pub struct _IncrementalFileState {
17+
pub(crate) struct _IncrementalFileState {
1818
completed_chunks: Vec<usize>,
1919
err: Option<io::Result<()>>,
2020
item: Option<Item>,
@@ -24,12 +24,12 @@ pub struct _IncrementalFileState {
2424
pub(super) type IncrementalFileState = Arc<Mutex<Option<_IncrementalFileState>>>;
2525

2626
#[derive(Default, Debug)]
27-
pub struct ImmediateUnpacker {
27+
pub(crate) struct ImmediateUnpacker {
2828
incremental_state: IncrementalFileState,
2929
}
3030

3131
impl ImmediateUnpacker {
32-
pub fn new() -> Self {
32+
pub(crate) fn new() -> Self {
3333
Self {
3434
..Default::default()
3535
}
@@ -148,7 +148,7 @@ pub(super) struct IncrementalFileWriter {
148148

149149
impl IncrementalFileWriter {
150150
#[allow(unused_variables)]
151-
pub fn new<P: AsRef<Path>>(
151+
pub(crate) fn new<P: AsRef<Path>>(
152152
path: P,
153153
mode: u32,
154154
state: IncrementalFileState,
@@ -172,7 +172,7 @@ impl IncrementalFileWriter {
172172
})
173173
}
174174

175-
pub fn chunk_submit(&mut self, chunk: FileBuffer) -> bool {
175+
pub(crate) fn chunk_submit(&mut self, chunk: FileBuffer) -> bool {
176176
if (self.state.lock().unwrap()).is_none() {
177177
return false;
178178
}

src/diskio/mod.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@
5151
// loss or errors in this model.
5252
// f) data gathering: record (name, bytes, start, duration)
5353
// write to disk afterwards as a csv file?
54-
pub mod immediate;
54+
pub(crate) mod immediate;
5555
#[cfg(test)]
5656
mod test;
57-
pub mod threaded;
57+
pub(crate) mod threaded;
5858

5959
use std::io::{self, Write};
6060
use std::ops::{Deref, DerefMut};
@@ -71,7 +71,7 @@ use threaded::PoolReference;
7171

7272
/// Carries the implementation specific data for complete file transfers into the executor.
7373
#[derive(Debug)]
74-
pub enum FileBuffer {
74+
pub(crate) enum FileBuffer {
7575
Immediate(Vec<u8>),
7676
// A reference to the object in the pool, and a handle to write to it
7777
Threaded(PoolReference),
@@ -131,7 +131,7 @@ pub(crate) const IO_CHUNK_SIZE: usize = 16_777_216;
131131

132132
/// Carries the implementation specific channel data into the executor.
133133
#[derive(Debug)]
134-
pub enum IncrementalFile {
134+
pub(crate) enum IncrementalFile {
135135
ImmediateReceiver,
136136
ThreadedReceiver(Receiver<FileBuffer>),
137137
}
@@ -176,41 +176,41 @@ pub enum IncrementalFile {
176176

177177
/// What kind of IO operation to perform
178178
#[derive(Debug)]
179-
pub enum Kind {
179+
pub(crate) enum Kind {
180180
Directory,
181181
File(FileBuffer),
182182
IncrementalFile(IncrementalFile),
183183
}
184184

185185
/// The details of the IO operation
186186
#[derive(Debug)]
187-
pub struct Item {
187+
pub(crate) struct Item {
188188
/// The path to operate on
189-
pub full_path: PathBuf,
189+
pub(crate) full_path: PathBuf,
190190
/// The operation to perform
191-
pub kind: Kind,
191+
pub(crate) kind: Kind,
192192
/// When the operation started
193-
pub start: Option<Instant>,
193+
start: Option<Instant>,
194194
/// Amount of time the operation took to finish
195-
pub finish: Option<Duration>,
195+
finish: Option<Duration>,
196196
/// The length of the file, for files (for stats)
197-
pub size: Option<usize>,
197+
size: Option<usize>,
198198
/// The result of the operation (could now be factored into CompletedIO...)
199-
pub result: io::Result<()>,
199+
pub(crate) result: io::Result<()>,
200200
/// The mode to apply
201-
pub mode: u32,
201+
mode: u32,
202202
}
203203

204204
#[derive(Debug)]
205-
pub enum CompletedIo {
205+
pub(crate) enum CompletedIo {
206206
/// A submitted Item has completed
207207
Item(Item),
208208
/// An IncrementalFile has completed a single chunk
209209
Chunk(usize),
210210
}
211211

212212
impl Item {
213-
pub fn make_dir(full_path: PathBuf, mode: u32) -> Self {
213+
pub(crate) fn make_dir(full_path: PathBuf, mode: u32) -> Self {
214214
Self {
215215
full_path,
216216
kind: Kind::Directory,
@@ -222,7 +222,7 @@ impl Item {
222222
}
223223
}
224224

225-
pub fn write_file(full_path: PathBuf, mode: u32, content: FileBuffer) -> Self {
225+
pub(crate) fn write_file(full_path: PathBuf, mode: u32, content: FileBuffer) -> Self {
226226
let len = content.len();
227227
Self {
228228
full_path,
@@ -235,7 +235,7 @@ impl Item {
235235
}
236236
}
237237

238-
pub fn write_file_segmented<'a>(
238+
pub(crate) fn write_file_segmented<'a>(
239239
full_path: PathBuf,
240240
mode: u32,
241241
state: IncrementalFileState,
@@ -261,7 +261,7 @@ impl Item {
261261
/// just allows the immediate codepath to get access to the Arc referenced state
262262
/// without holding a lifetime reference to the executor, as the threaded code
263263
/// path is all message passing.
264-
pub enum IncrementalFileState {
264+
pub(crate) enum IncrementalFileState {
265265
Threaded,
266266
Immediate(immediate::IncrementalFileState),
267267
}
@@ -294,7 +294,7 @@ impl IncrementalFileState {
294294
/// Trait object for performing IO. At this point the overhead
295295
/// of trait invocation is not a bottleneck, but if it becomes
296296
/// one we could consider an enum variant based approach instead.
297-
pub trait Executor {
297+
pub(crate) trait Executor {
298298
/// Perform a single operation.
299299
/// During overload situations previously queued items may
300300
/// need to be completed before the item is accepted:
@@ -332,7 +332,7 @@ pub trait Executor {
332332

333333
/// Trivial single threaded IO to be used from executors.
334334
/// (Crazy sophisticated ones can obviously ignore this)
335-
pub fn perform<F: Fn(usize)>(item: &mut Item, chunk_complete_callback: F) {
335+
pub(crate) fn perform<F: Fn(usize)>(item: &mut Item, chunk_complete_callback: F) {
336336
// directories: make them, TODO: register with the dir existence cache.
337337
// Files, write them.
338338
item.result = match &mut item.kind {
@@ -361,7 +361,7 @@ pub fn perform<F: Fn(usize)>(item: &mut Item, chunk_complete_callback: F) {
361361
}
362362

363363
#[allow(unused_variables)]
364-
pub fn write_file<P: AsRef<Path>, C: AsRef<[u8]>>(
364+
pub(crate) fn write_file<P: AsRef<Path>, C: AsRef<[u8]>>(
365365
path: P,
366366
contents: C,
367367
mode: u32,
@@ -392,7 +392,7 @@ pub fn write_file<P: AsRef<Path>, C: AsRef<[u8]>>(
392392
}
393393

394394
#[allow(unused_variables)]
395-
pub fn write_file_incremental<P: AsRef<Path>, F: Fn(usize)>(
395+
pub(crate) fn write_file_incremental<P: AsRef<Path>, F: Fn(usize)>(
396396
path: P,
397397
content_callback: &mut IncrementalFile,
398398
mode: u32,
@@ -437,15 +437,15 @@ pub fn write_file_incremental<P: AsRef<Path>, F: Fn(usize)>(
437437
Ok(())
438438
}
439439

440-
pub fn create_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
440+
pub(crate) fn create_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
441441
let path = path.as_ref();
442442
let path_display = format!("{}", path.display());
443443
trace_scoped!("create_dir", "name": path_display);
444444
std::fs::create_dir(path)
445445
}
446446

447447
/// Get the executor for disk IO.
448-
pub fn get_executor<'a>(
448+
pub(crate) fn get_executor<'a>(
449449
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
450450
ram_budget: usize,
451451
) -> Result<Box<dyn Executor + 'a>> {

src/diskio/threaded.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::utils::notifications::Notification;
1818
use crate::utils::units::Unit;
1919

2020
#[derive(Copy, Clone, Debug, Enum)]
21-
pub enum Bucket {
21+
pub(crate) enum Bucket {
2222
FourK,
2323
EightK,
2424
OneM,
@@ -27,13 +27,13 @@ pub enum Bucket {
2727
}
2828

2929
#[derive(Debug)]
30-
pub enum PoolReference {
30+
pub(crate) enum PoolReference {
3131
Owned(OwnedRef<Vec<u8>>, Arc<sharded_slab::Pool<Vec<u8>>>),
3232
Mut(OwnedRefMut<Vec<u8>>, Arc<sharded_slab::Pool<Vec<u8>>>),
3333
}
3434

3535
impl PoolReference {
36-
pub fn clear(&mut self) {
36+
pub(crate) fn clear(&mut self) {
3737
match self {
3838
PoolReference::Mut(orm, pool) => {
3939
pool.clear(orm.key());
@@ -96,7 +96,7 @@ impl fmt::Debug for Pool {
9696
}
9797
}
9898

99-
pub struct Threaded<'a> {
99+
pub(crate) struct Threaded<'a> {
100100
n_files: Arc<AtomicUsize>,
101101
pool: threadpool::ThreadPool,
102102
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
@@ -108,7 +108,7 @@ pub struct Threaded<'a> {
108108

109109
impl<'a> Threaded<'a> {
110110
/// Construct a new Threaded executor.
111-
pub fn new(
111+
pub(crate) fn new(
112112
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
113113
thread_count: usize,
114114
ram_budget: usize,

0 commit comments

Comments
 (0)