Skip to content

Commit

Permalink
Resolve warnings on Linux with no default features
Browse files Browse the repository at this point in the history
`cargo check --target x86_64-unknown-linux-gnu --no-default-features`

    warning: function `get_all_utf8_data_from_file` is never used
      --> src/unix/linux/utils.rs:15:15
       |
    15 | pub(crate) fn get_all_utf8_data_from_file(file: &mut File, size: usize) -> io::Result<String> {
       |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = note: `#[warn(dead_code)]` on by default

    warning: function `get_all_utf8_data` is never used
      --> src/unix/linux/utils.rs:22:15
       |
    22 | pub(crate) fn get_all_utf8_data<P: AsRef<Path>>(file_path: P, size: usize) -> io::Result<String> {
       |               ^^^^^^^^^^^^^^^^^

    warning: function `to_cpath` is never used
      --> src/unix/linux/utils.rs:88:15
       |
    88 | pub(crate) fn to_cpath(path: &std::path::Path) -> Vec<u8> {
       |               ^^^^^^^^
  • Loading branch information
dtolnay committed Dec 7, 2024
1 parent 4931dff commit 2be51d1
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/unix/linux/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Take a look at the license at the top of the repository in the LICENSE file.

#[cfg(any(feature = "disk", feature = "system"))]
use std::fs::File;
#[cfg(any(feature = "disk", feature = "system"))]
use std::io::{self, Read, Seek};
#[cfg(any(feature = "disk", feature = "system"))]
use std::path::Path;

#[cfg(feature = "system")]
Expand All @@ -12,13 +15,15 @@ pub(crate) fn get_all_data_from_file(file: &mut File, size: usize) -> io::Result
Ok(buf)
}

#[cfg(any(feature = "disk", feature = "system"))]
pub(crate) fn get_all_utf8_data_from_file(file: &mut File, size: usize) -> io::Result<String> {
let mut buf = String::with_capacity(size);
file.rewind()?;
file.read_to_string(&mut buf)?;
Ok(buf)
}

#[cfg(any(feature = "disk", feature = "system"))]
pub(crate) fn get_all_utf8_data<P: AsRef<Path>>(file_path: P, size: usize) -> io::Result<String> {
let mut file = File::open(file_path.as_ref())?;
get_all_utf8_data_from_file(&mut file, size)
Expand Down Expand Up @@ -85,6 +90,7 @@ pub(crate) fn to_u64(v: &[u8]) -> u64 {
}

/// Converts a path to a NUL-terminated `Vec<u8>` suitable for use with C functions.
#[cfg(feature = "disk")]
pub(crate) fn to_cpath(path: &std::path::Path) -> Vec<u8> {
use std::{ffi::OsStr, os::unix::ffi::OsStrExt};

Expand Down

0 comments on commit 2be51d1

Please sign in to comment.