Struct rotary::interleaved::ChannelMut [−][src]
A mutable reference to a channel in a buffer.
Implementations
impl<'a, T> ChannelMut<'a, T>
[src]
pub fn get(&self, frame: usize) -> Option<T> where
T: Copy,
[src]
T: Copy,
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]
T: Debug,
impl<T> Eq for ChannelMut<'_, T> where
T: Eq,
[src]
T: Eq,
impl<T> Hash for ChannelMut<'_, T> where
T: Hash,
[src]
T: Hash,
fn hash<H: Hasher>(&self, state: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T> Ord for ChannelMut<'_, T> where
T: Ord,
[src]
T: Ord,
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<T> PartialEq<ChannelMut<'_, T>> for ChannelMut<'_, T> where
T: PartialEq,
[src]
T: PartialEq,
impl<T> PartialOrd<ChannelMut<'_, T>> for ChannelMut<'_, T> where
T: PartialOrd,
[src]
T: PartialOrd,
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T> Send for ChannelMut<'_, T> where
T: Send,
[src]
T: Send,
impl<T> Sync for ChannelMut<'_, T> where
T: Sync,
[src]
T: Sync,
Auto Trait Implementations
impl<'a, T> RefUnwindSafe for ChannelMut<'a, T> where
T: RefUnwindSafe,
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,