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

Conversation

andrewcsmith
Copy link
Contributor

No description provided.

@@ -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!

@mitchmindtree
Copy link
Member

It looks like there are a couple compile errors showing up in the nightly build when type checking with --no-default-features (without std)

@andrewcsmith
Copy link
Contributor Author

I was wondering what that failure was and how to reproduce it. Yeah, just need to import Box explicitly.

@mitchmindtree mitchmindtree merged commit 45702f1 into RustAudio:master Sep 7, 2017
mitchmindtree added a commit to mitchmindtree/dasp that referenced this pull request Oct 10, 2017
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 👍
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants