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 total and used. All other methods exposed by this trait are there in case you’re intending to calculate memory usage on your own.

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 free(&self) -> Result<u64, ReadoutError> {
        // Get the amount of free memory
        Ok(256 * 1024) // Return 256mb in kilobytes.
    }

    fn buffers(&self) -> Result<u64, ReadoutError> {
        // Get the current memory value for buffers
        Ok(64 * 1024) // Return 64mb in kilobytes.
    }

    fn cached(&self) -> Result<u64, ReadoutError> {
        // Get the amount of cached content in memory
        Ok(128 * 1024) // Return 128mb in kilobytes.
    }

    fn reclaimable(&self) -> Result<u64, ReadoutError> {
        // Get the amount of reclaimable memory
        Ok(64 * 1024) // Return 64mb 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.

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