-
Notifications
You must be signed in to change notification settings - Fork 64
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
Add Self: Sized constraint to by_ref #66
Conversation
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
It looks like there are a couple compile errors showing up in the nightly build when type checking with |
I was wondering what that failure was and how to reproduce it. Yeah, just need to import Box explicitly. |
This extends the existing implementation for `&'a mut S where S: Signal` and `Box<Signal>` to be a little more general. E.g. `&mut my_signal as &mut Signal` now produces a `&mut Signal` trait object which also implements `Signal`. Boxed signals no longer require the `Sized` bound in order to implement `Signal` themselves, E.g. the `Sized` bound in `Box<Signal<Frame=[f32; 2]> + Sized>` is no longer necessary. These changes now reflect the implementations of `Iterator` for `&mut Iterator` and `Box<Iterator>` in the std library. cc @andrewcsmith this alters the `Signal` impl for `Box<Signal>` introduced in RustAudio#66, however I don't believe this is a breaking change as it should be strictly more general 👍
No description provided.