Skip to content

Commit

Permalink
free: derive Default for MemInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
cakebaker committed Mar 31, 2024
1 parent 9da9fc7 commit 00e7190
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/uu/free/src/free.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const ABOUT: &str = help_about!("free.md");
const USAGE: &str = help_usage!("free.md");

/// The unit of number is [UnitMultiplier::Bytes]
#[derive(Default)]
struct MemInfo {
total: u64,
free: u64,
Expand All @@ -49,18 +50,7 @@ struct MemInfo {
#[cfg(target_os = "linux")]
fn parse_meminfo() -> Result<MemInfo, Error> {
let contents = fs::read_to_string("/proc/meminfo")?;
let mut mem_info = MemInfo {
total: 0,
free: 0,
available: 0,
shared: 0,
buffers: 0,
cached: 0,
swap_total: 0,
swap_free: 0,
swap_used: 0,
reclaimable: 0,
};
let mut mem_info = MemInfo::default();

for line in contents.lines() {
if let Some((key, value)) = line.split_once(':') {
Expand Down Expand Up @@ -107,6 +97,12 @@ fn parse_meminfo() -> Result<MemInfo, Box<dyn std::error::Error>> {
Ok(mem_info)
}

// TODO: implement function
#[cfg(target_os = "windows")]
fn parse_meminfo() -> Result<MemInfo, Box<dyn std::error::Error>> {
Ok(MemInfo::default())
}

#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args)?;
Expand Down

0 comments on commit 00e7190

Please sign in to comment.