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/meminfopseudofile; - 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
impl MemInfo
Sourcepub fn new() -> Result<Self>
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.
Sourcepub fn with_capacity(capacity: usize) -> Result<Self>
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.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the internal buffer, removing its content without affecting its allocated capacity.
Sourcepub fn shrink_to_fit(&mut self)
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.
Sourcepub fn shrink_to(&mut self, capacity: usize)
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.
Sourcepub fn seek(&mut self, pos: SeekFrom) -> Result<u64>
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.
Sourcepub fn read_exact(&mut self, bytes: u64) -> Result<usize>
pub fn read_exact(&mut self, bytes: u64) -> Result<usize>
Sourcepub fn read(&mut self) -> Result<usize>
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.
Sourcepub fn read_to_end(&mut self) -> Result<usize>
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.
Sourcepub fn parse(&self) -> impl Iterator<Item = MemInfoEntry<'_>>
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).
Sourcepub fn parse_extended(&self) -> impl Iterator<Item = MemInfoEntryExtended<'_>>
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.