Struct rotary::interleaved::ChannelMut[][src]

pub struct ChannelMut<'a, T> { /* fields omitted */ }

A mutable reference to a channel in a buffer.

See crate::Interleaved::get_mut.

Implementations

impl<'a, T> ChannelMut<'a, T>[src]

pub fn get(&self, frame: usize) -> Option<T> where
    T: Copy
[src]

Get a reference to a frame.

Examples

let mut buffer = rotary::Interleaved::<f32>::with_topology(2, 256);

let left = buffer.get(0).unwrap();

assert_eq!(left.get(64), Some(0.0));
assert_eq!(left.get(255), Some(0.0));
assert_eq!(left.get(256), None);

pub fn get_mut(&mut self, frame: usize) -> Option<&mut T>[src]

Get a mutable reference to a frame.

Examples

let mut buffer = rotary::Interleaved::<f32>::with_topology(2, 256);

let mut left = buffer.get_mut(0).unwrap();

assert_eq!(left.get(64), Some(0.0));
*left.get_mut(64).unwrap() = 1.0;
assert_eq!(left.get(64), Some(1.0));

pub fn into_mut(self, frame: usize) -> Option<&'a mut T>[src]

Convert the mutable channel into a single mutable frame.

This is necessary in case you need to build a structure which wraps a mutable channel and you want it to return the same lifetime as the mutable channel is associated with.

Examples

This does not build:

struct Foo<'a> {
    left: rotary::interleaved::ChannelMut<'a, f32>,
}

impl<'a> Foo<'a> {
    fn get_mut(&mut self, frame: usize) -> Option<&'a mut f32> {
        self.left.get_mut(frame)
    }
}

let mut buffer = rotary::Interleaved::<f32>::with_topology(2, 256);

let mut foo = Foo {
    left: buffer.get_mut(0).unwrap(),
};

*foo.get_mut(64).unwrap() = 1.0;
assert_eq!(buffer.frame(0, 64), Some(1.0));
   error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements
   --> examples\compile-fail.rs:7:19
    |
  7 |         self.left.get_mut(frame)
    |                   ^^^^^^^
    |

Because if it did, it would be permitted to extract multiple mutable references to potentially the same frame with the lifetime 'a, because Foo holds onto the mutable channel.

The way we can work around this is by allowing a function to consume the mutable channel. And we can do that with ChannelMut::into_mut.


impl<'a> Foo<'a> {
    fn into_mut(self, frame: usize) -> Option<&'a mut f32> {
        self.left.into_mut(frame)
    }
}

let mut buffer = rotary::Interleaved::<f32>::with_topology(2, 256);

let mut foo = Foo {
    left: buffer.get_mut(0).unwrap(),
};

*foo.into_mut(64).unwrap() = 1.0;
assert_eq!(buffer.frame(0, 64), Some(1.0));

pub fn iter(&self) -> ChannelIter<'_, T>[src]

Construct an iterator over the current channel.

pub fn iter_mut(&mut self) -> ChannelIterMut<'_, T>[src]

Construct a mutable iterator over the current channel.

Trait Implementations

impl<T> Debug for ChannelMut<'_, T> where
    T: Debug
[src]

impl<T> Eq for ChannelMut<'_, T> where
    T: Eq
[src]

impl<T> Hash for ChannelMut<'_, T> where
    T: Hash
[src]

impl<T> Ord for ChannelMut<'_, T> where
    T: Ord
[src]

impl<T> PartialEq<ChannelMut<'_, T>> for ChannelMut<'_, T> where
    T: PartialEq
[src]

impl<T> PartialOrd<ChannelMut<'_, T>> for ChannelMut<'_, T> where
    T: PartialOrd
[src]

impl<T> Send for ChannelMut<'_, T> where
    T: Send
[src]

impl<T> Sync for ChannelMut<'_, T> where
    T: Sync
[src]

Auto Trait Implementations

impl<'a, T> RefUnwindSafe for ChannelMut<'a, T> where
    T: RefUnwindSafe

impl<'a, T> Unpin for ChannelMut<'a, T>

impl<'a, T> !UnwindSafe for ChannelMut<'a, T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.