MemInfo

Struct MemInfo 

Source
pub struct MemInfo { /* private fields */ }
Expand description

An object providing buffered access to the /proc/meminfo pseudofile.

This struct is responsible for retrieving memory-related information about the system. Its constructor attempts to:

  • open the /proc/meminfo pseudofile;
  • read its data into the internal buffer;
  • rewind to the beginning of the file stream, in order to prepare for the next read call.

Implementations§

Source§

impl MemInfo

Source

pub fn new() -> Result<Self>

Constructs a new instance, opening the /proc/meminfo pseudofile, reading all of its data into the internal buffer and rewinding to the beginning of the stream.

§Errors

This function returns an error if /proc/meminfo could not be opened, read into the internal buffer, or rewinded.

Source

pub fn with_capacity(capacity: usize) -> Result<Self>

Constructs a new intance, opening the /proc/meminfo pseudofile, reading its data into the internal buffer up to buffer capacity and rewinding to the beginning of the stream.

§Errors

This function returns an error if /proc/meminfo could not be opened, read into the internal buffer, or rewinded.

Source

pub fn clear(&mut self)

Clears the internal buffer, removing its content without affecting its allocated capacity.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the internal buffer as much as possible close to the buffer length.

§Notes

This method does NOT clear the internal buffer before attempting to resize its capacity.

If the current buffer capacity matches the buffer length, calling this method will result in a no-op.

Source

pub fn shrink_to(&mut self, capacity: usize)

Shrinks the capacity of the internal buffer with a lower capacity bound.

§Notes

This method does NOT clear the internal buffer before attempting to resize its capacity, meaning that specifying a size smaller the buffer length is equivalent to calling MemInfo::shrink_to_fit.

Also, if the current buffer capacity is smaller than the specified size, this method will result in a no-op.

Source

pub fn rewind(&mut self) -> Result<()>

Rewinds /proc/meminfo to the beginning of the stream.

§Notes

Calling this method is equivalent to calling self.seek(SeekFrom::Start(0)).

§Errors

Returns an error if /proc/meminfo could not be rewinded.

Source

pub fn seek(&mut self, pos: SeekFrom) -> Result<u64>

Seeks /proc/meminfo to an offset and returns the new position from the start of the stream.

§Errors

Returns an error if /proc/meminfo could not be sought.

Source

pub fn read_exact(&mut self, bytes: u64) -> Result<usize>

Reads an exact number of bytes from /proc/meminfo into the internal buffer.

§Notes

The buffered data is NOT cleared before the new data is read into the buffer.

§Errors

This method returns an error if /proc/meminfo could not be read into the internal buffer.

Source

pub fn read(&mut self) -> Result<usize>

Reads the exact number of bytes from /proc/meminfo required to fill the internal buffer and returns the number of bytes read.

§Notes

The buffered data is NOT cleared before the new data is read into the buffer.

§Errors

This method returns an error if /proc/meminfo could not be read into the internal buffer.

Source

pub fn read_to_end(&mut self) -> Result<usize>

Reads bytes from /proc/meminfo until EOF into the internal buffer and returns the total number of bytes read.

§Notes
  • The buffered data is NOT cleared before the new data is read into the buffer.
  • If the internal buffer is not large enough, this method will allocate for data to fit.
§Errors

This method returns an error if /proc/meminfo could not be read into the internal buffer.

Source

pub fn parse(&self) -> impl Iterator<Item = MemInfoEntry<'_>>

Returns a lazy iterator over parsed /proc/meminfo entries.

§Notes

For richer /proc/meminfo entry information see MemInfo::parse_extended, which is an extension of this methods, since it also collects each entry’s start and end positions in the file stream (useful for MemInfo::seek calls).

Source

pub fn parse_extended(&self) -> impl Iterator<Item = MemInfoEntryExtended<'_>>

Returns an iterator over parsed /proc/meminfo entries. Compared to MemInfo::parse, in this case the elements being iterated over are extended with information about the start and end bytes of the file they were parsed from.

§Notes

For simpler and slimmer /proc/meminfo entry information see MemInfo::parse.

Trait Implementations§

Source§

impl Debug for MemInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.