Trait libmacchina::traits::MemoryReadout[][src]

pub trait MemoryReadout {
    fn new() -> Self;

    fn total(&self) -> Result<u64, ReadoutError> { ... }
fn free(&self) -> Result<u64, ReadoutError> { ... }
fn buffers(&self) -> Result<u64, ReadoutError> { ... }
fn cached(&self) -> Result<u64, ReadoutError> { ... }
fn reclaimable(&self) -> Result<u64, ReadoutError> { ... }
fn used(&self) -> Result<u64, ReadoutError> { ... } }
Expand description

This trait provides common functions for querying the current memory state of the host device, most notably free and used.

Example

use libmacchina::traits::MemoryReadout;
use libmacchina::traits::ReadoutError;

pub struct MacOSMemoryReadout;

impl MemoryReadout for MacOSMemoryReadout {
    fn new() -> Self {
        MacOSMemoryReadout {}
    }

    fn total(&self) -> Result<u64, ReadoutError> {
        // Get the total physical memory for the machine
        Ok(512 * 1024) // Return 512mb in kilobytes.
    }

    fn used(&self) -> Result<u64, ReadoutError> {
        // Get the currently used memory.
        Ok(256 * 1024) // Return 256mb in kilobytes.
    }
}

Required methods

Creates a new instance of the structure which implements this trait.

Provided methods

This function should return the total available memory in kilobytes.

This function should return the free available memory in kilobytes.

This function should return the current memory value for buffers in kilobytes.

This function should return the amount of cached content in memory in kilobytes.

This function should return the amount of reclaimable memory in kilobytes.

This function should return the amount of currently used memory in kilobytes.

Implementors