Skip to content

Commit

Permalink
Changed Buffer::len() to Buffer::capacity(). Makes more sense.
Browse files Browse the repository at this point in the history
  • Loading branch information
fpagliughi committed Dec 28, 2019
1 parent 8b885ac commit 801c071
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ use super::*;
pub struct Buffer {
/// The underlying buffer from the C library
pub(crate) buf: *mut ffi::iio_buffer,
/// The sample count (# samples from each channel)
pub(crate) len: usize,
/// The buffer capacity (# samples from each channel)
pub(crate) cap: usize,
// this holds the refcount for libiio
#[allow(dead_code)]
pub(crate) ctx: Context,
}

impl Buffer {
/// Get the buffer sample count.
/// This is the number of items from each channel that the buffer can hold.
pub fn len(&self) -> usize { self.len }
/// Get the buffer capacity in number of samples from each channel that
/// the buffer can hold.
pub fn capacity(&self) -> usize { self.cap }

/// Gets a pollable file descriptor for the buffer.
/// This can be used to determine when refill() or push() can be called
Expand Down
4 changes: 2 additions & 2 deletions src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ impl Channel {
bail!("Wrong data type");
}

let n = buf.len();
let n = buf.capacity();
let sz_item = mem::size_of::<T>();
let sz_in = n * sz_item;

Expand All @@ -447,7 +447,7 @@ impl Channel {
bail!("Wrong data type");
}

let n = buf.len();
let n = buf.capacity();
let sz_item = mem::size_of::<T>();
let sz_in = n * sz_item;

Expand Down
2 changes: 1 addition & 1 deletion src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl Device {
pub fn create_buffer(&self, sample_count: usize, cyclic: bool) -> Result<Buffer> {
let buf = unsafe { ffi::iio_device_create_buffer(self.dev, sample_count, cyclic) };
if buf.is_null() { bail!(SysError(Errno::last())); }
Ok(Buffer { buf, len: sample_count, ctx: self.context() })
Ok(Buffer { buf, cap: sample_count, ctx: self.context() })
}

/// Gets the number of buffer-specific attributes
Expand Down

0 comments on commit 801c071

Please sign in to comment.