Skip to content

Commit

Permalink
Rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
vcfxb committed May 24, 2024
1 parent c2a7980 commit ea959de
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
2 changes: 0 additions & 2 deletions wright/src/reporting/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ pub fn draw<W: WriteColor>(
Ok(())
}



#[cfg(test)]
mod tests {
use crate::reporting::Diagnostic;
Expand Down
2 changes: 1 addition & 1 deletion wright/src/source_tracking/immutable_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl AsRef<str> for ImmutableStringInner {
match self {
ImmutableStringInner::Static(str) => str,
ImmutableStringInner::Owned(str) => str,

#[cfg(feature = "file_memmap")]
ImmutableStringInner::LockedFile { mem_map, .. } => {
// Get a direct reference to the data that is in the memory map.
Expand Down
29 changes: 14 additions & 15 deletions wright/src/source_tracking/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ use std::io;
use std::path::PathBuf;

#[cfg(feature = "file_memmap")]
use std::{
sync::mpsc,
thread,
time::Duration
};
use std::{sync::mpsc, thread, time::Duration};

#[cfg(feature = "file_memmap")]
use fs4::FileExt;
Expand Down Expand Up @@ -67,8 +63,8 @@ impl Source {

/// Attempt to memory map a file from the disk into a [Source].
/// This will likely be faster than reading the file in some cases, and almost always more memory efficient.
///
/// This requires the "file_memmap" feature.
///
/// This requires the "file_memmap" feature.
#[cfg(feature = "file_memmap")]
pub fn new_mapped_from_disk(path: PathBuf) -> io::Result<Self> {
// Make a one-off enum here to use for channel messages.
Expand Down Expand Up @@ -163,19 +159,22 @@ impl Source {
}

/// Read a file from the disk into a source. This reads the file, which may take longer than memory mapping it
/// as done in [Self::new_mapped_from_disk]. This does not require the same features and dependencies as memory
/// mapped operations though. This stores the whole file in memory, rather than mapping virtual memory to the disk.
/// That makes this less memory efficient than [Self::new_mapped_from_disk], which may be important on systems
/// where ram is constrained.
///
/// Use this if the "file_memmap" is not available for some reason.
/// as done in [Self::new_mapped_from_disk]. This does not require the same features and dependencies as memory
/// mapped operations though. This stores the whole file in memory, rather than mapping virtual memory to the disk.
/// That makes this less memory efficient than [Self::new_mapped_from_disk], which may be important on systems
/// where ram is constrained.
///
/// Use this if the "file_memmap" is not available for some reason.
pub fn new_read_from_disk(path: PathBuf) -> io::Result<Self> {
// Open the file for reading.
let file: File = File::open(&path)?;
// Read the file to a string.
let content: String = io::read_to_string(&file)?;
// Turn that into a Source.
Ok(Self::new(FileName::Real(path), ImmutableString::new_owned(content.into_boxed_str())))
// Turn that into a Source.
Ok(Self::new(
FileName::Real(path),
ImmutableString::new_owned(content.into_boxed_str()),
))
}

/// Get byte indices of where lines start in this [Source].
Expand Down

0 comments on commit ea959de

Please sign in to comment.