Skip to content

Commit ec202e0

Browse files
committed
Make all diskio functions and structs crate-private
Make some fields private
1 parent 11c855e commit ec202e0

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
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, 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
}
@@ -136,7 +136,7 @@ pub(super) struct IncrementalFileWriter {
136136

137137
impl IncrementalFileWriter {
138138
#[allow(unused_variables)]
139-
pub fn new<P: AsRef<Path>>(
139+
pub(crate) fn new<P: AsRef<Path>>(
140140
path: P,
141141
mode: u32,
142142
state: IncrementalFileState,
@@ -160,7 +160,7 @@ impl IncrementalFileWriter {
160160
})
161161
}
162162

163-
pub fn chunk_submit(&mut self, chunk: Vec<u8>) -> bool {
163+
pub(crate) fn chunk_submit(&mut self, chunk: Vec<u8>) -> bool {
164164
if (self.state.lock().unwrap()).is_none() {
165165
return false;
166166
}

src/diskio/mod.rs

+23-23
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::path::{Path, PathBuf};
@@ -69,7 +69,7 @@ use crate::utils::notifications::Notification;
6969

7070
/// Carries the implementation specific channel data into the executor.
7171
#[derive(Debug)]
72-
pub enum IncrementalFile {
72+
pub(crate) enum IncrementalFile {
7373
ImmediateReceiver,
7474
ThreadedReceiver(Receiver<Vec<u8>>),
7575
}
@@ -114,41 +114,41 @@ pub enum IncrementalFile {
114114

115115
/// What kind of IO operation to perform
116116
#[derive(Debug)]
117-
pub enum Kind {
117+
pub(crate) enum Kind {
118118
Directory,
119119
File(Vec<u8>),
120120
IncrementalFile(IncrementalFile),
121121
}
122122

123123
/// The details of the IO operation
124124
#[derive(Debug)]
125-
pub struct Item {
125+
pub(crate) struct Item {
126126
/// The path to operate on
127-
pub full_path: PathBuf,
127+
pub(crate) full_path: PathBuf,
128128
/// The operation to perform
129-
pub kind: Kind,
129+
pub(crate) kind: Kind,
130130
/// When the operation started
131-
pub start: Option<Instant>,
131+
start: Option<Instant>,
132132
/// Amount of time the operation took to finish
133-
pub finish: Option<Duration>,
133+
finish: Option<Duration>,
134134
/// The length of the file, for files (for stats)
135-
pub size: Option<usize>,
135+
size: Option<usize>,
136136
/// The result of the operation (could now be factored into CompletedIO...)
137-
pub result: io::Result<()>,
137+
pub(crate) result: io::Result<()>,
138138
/// The mode to apply
139-
pub mode: u32,
139+
mode: u32,
140140
}
141141

142142
#[derive(Debug)]
143-
pub enum CompletedIo {
143+
pub(crate) enum CompletedIo {
144144
/// A submitted Item has completed
145145
Item(Item),
146146
/// An IncrementalFile has completed a single chunk
147147
Chunk(usize),
148148
}
149149

150150
impl Item {
151-
pub fn make_dir(full_path: PathBuf, mode: u32) -> Self {
151+
pub(crate) fn make_dir(full_path: PathBuf, mode: u32) -> Self {
152152
Self {
153153
full_path,
154154
kind: Kind::Directory,
@@ -160,7 +160,7 @@ impl Item {
160160
}
161161
}
162162

163-
pub fn write_file(full_path: PathBuf, content: Vec<u8>, mode: u32) -> Self {
163+
pub(crate) fn write_file(full_path: PathBuf, content: Vec<u8>, mode: u32) -> Self {
164164
let len = content.len();
165165
Self {
166166
full_path,
@@ -173,7 +173,7 @@ impl Item {
173173
}
174174
}
175175

176-
pub fn write_file_segmented<'a>(
176+
pub(crate) fn write_file_segmented<'a>(
177177
full_path: PathBuf,
178178
mode: u32,
179179
state: IncrementalFileState,
@@ -199,7 +199,7 @@ impl Item {
199199
/// just allows the immediate codepath to get access to the Arc referenced state
200200
/// without holding a lifetime reference to the executor, as the threaded code
201201
/// path is all message passing.
202-
pub enum IncrementalFileState {
202+
pub(crate) enum IncrementalFileState {
203203
Threaded,
204204
Immediate(immediate::IncrementalFileState),
205205
}
@@ -232,7 +232,7 @@ impl IncrementalFileState {
232232
/// Trait object for performing IO. At this point the overhead
233233
/// of trait invocation is not a bottleneck, but if it becomes
234234
/// one we could consider an enum variant based approach instead.
235-
pub trait Executor {
235+
pub(crate) trait Executor {
236236
/// Perform a single operation.
237237
/// During overload situations previously queued items may
238238
/// need to be completed before the item is accepted:
@@ -262,7 +262,7 @@ pub trait Executor {
262262

263263
/// Trivial single threaded IO to be used from executors.
264264
/// (Crazy sophisticated ones can obviously ignore this)
265-
pub fn perform<F: Fn(usize)>(item: &mut Item, chunk_complete_callback: F) {
265+
pub(crate) fn perform<F: Fn(usize)>(item: &mut Item, chunk_complete_callback: F) {
266266
// directories: make them, TODO: register with the dir existence cache.
267267
// Files, write them.
268268
item.result = match &mut item.kind {
@@ -281,7 +281,7 @@ pub fn perform<F: Fn(usize)>(item: &mut Item, chunk_complete_callback: F) {
281281
}
282282

283283
#[allow(unused_variables)]
284-
pub fn write_file<P: AsRef<Path>, C: AsRef<[u8]>>(
284+
pub(crate) fn write_file<P: AsRef<Path>, C: AsRef<[u8]>>(
285285
path: P,
286286
contents: C,
287287
mode: u32,
@@ -312,7 +312,7 @@ pub fn write_file<P: AsRef<Path>, C: AsRef<[u8]>>(
312312
}
313313

314314
#[allow(unused_variables)]
315-
pub fn write_file_incremental<P: AsRef<Path>, F: Fn(usize)>(
315+
pub(crate) fn write_file_incremental<P: AsRef<Path>, F: Fn(usize)>(
316316
path: P,
317317
content_callback: &mut IncrementalFile,
318318
mode: u32,
@@ -357,15 +357,15 @@ pub fn write_file_incremental<P: AsRef<Path>, F: Fn(usize)>(
357357
Ok(())
358358
}
359359

360-
pub fn create_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
360+
pub(crate) fn create_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
361361
let path = path.as_ref();
362362
let path_display = format!("{}", path.display());
363363
trace_scoped!("create_dir", "name": path_display);
364364
std::fs::create_dir(path)
365365
}
366366

367367
/// Get the executor for disk IO.
368-
pub fn get_executor<'a>(
368+
pub(crate) fn get_executor<'a>(
369369
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
370370
) -> Result<Box<dyn Executor + 'a>> {
371371
// If this gets lots of use, consider exposing via the config file.

src/diskio/threaded.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl Default for Task {
2525
}
2626
}
2727

28-
pub struct Threaded<'a> {
28+
pub(crate) struct Threaded<'a> {
2929
n_files: Arc<AtomicUsize>,
3030
pool: threadpool::ThreadPool,
3131
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
@@ -34,7 +34,10 @@ pub struct Threaded<'a> {
3434
}
3535

3636
impl<'a> Threaded<'a> {
37-
pub fn new(notify_handler: Option<&'a dyn Fn(Notification<'_>)>, thread_count: usize) -> Self {
37+
pub(crate) fn new(
38+
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
39+
thread_count: usize,
40+
) -> Self {
3841
// Defaults to hardware thread count threads; this is suitable for
3942
// our needs as IO bound operations tend to show up as write latencies
4043
// rather than close latencies, so we don't need to look at

0 commit comments

Comments
 (0)