Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Self: Sized constraint to by_ref #66

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,9 @@ pub trait Signal {
/// assert_eq!(signal.next(), [4]);
/// }
/// ```
fn by_ref(&mut self) -> &mut Self {
fn by_ref(&mut self) -> &mut Self
where Self: Sized
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still unsure why this is necessary? I'm happy to add it if it is necesary, I'm just curious what cause for it is - is there some compile error or warning if we don't have this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it means that Signal is not object-safe because there's a method that uses Self in its return type. This disallows that. The advantage to object safety is that was can return abstract Box<Signal> from a function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh I see, I don't often use trait objects so haven't run into this for a while, but that makes sense!

{
self
}
}
Expand Down Expand Up @@ -1042,6 +1044,16 @@ pub fn noise_simplex<S>(phase: Phase<S>) -> NoiseSimplex<S> {

//// Trait Implementations for Signal Types.

impl<F> Signal for Box<Signal<Frame=F>>
where F: Frame
{
type Frame = F;
#[inline]
fn next(&mut self) -> Self::Frame {
use core::ops::DerefMut;
self.deref_mut().next()
}
}

impl<I> Signal for FromIterator<I>
where I: Iterator,
Expand Down