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 tests for ext traits + rename traits #18

Merged
merged 3 commits into from
Jun 6, 2019

Conversation

mmastrac
Copy link
Contributor

This adds tests for the ext traits. I've also renamed the traits to FutureTimerExt and StreamTimerExt because they were conflicting with the built-in futures FutureExt and StreamExt.

@yoshuawuyts
Copy link
Contributor

because they were conflicting with the built-in futures FutureExt and StreamExt

If we're to follow the extension trait naming conventions defined in RFC0445 we should probably keep naming these traits FutureExt and StreamExt.

Also I just checked in the playground, and it doesn't seem like extension trait names conflict with each other. The following compiles without a problem:

mod foo {
    pub trait ResultExt {}
    impl<T,E> ResultExt for Result<T, E> {}
}

mod bar {
    pub trait ResultExt {}
    impl<T,E> ResultExt for Result<T, E> {}
}

use foo::*;
use bar::*;

fn main () -> Result<(), std::io::Error> {
    Ok(())
}

@mmastrac
Copy link
Contributor Author

Interesting. I had some local conflicts, but I can try to poke around them a bit more and see if I can resolve it.

@mmastrac
Copy link
Contributor Author

mmastrac commented May 30, 2019

Ok, so it looks like Rust allows you to import the same type more than one time, but trying to use extension methods from both just doesn't work. I modified your test case to show this happening:

mod foo {
    pub trait ResultExt {
        fn a(&self);
    }
    impl<T,E> ResultExt for Result<T, E> {
        fn a(&self) {}
    }
}

mod bar {
    pub trait ResultExt {
        fn b(&self);
    }
    impl<T,E> ResultExt for Result<T, E> {
        fn b(&self) {}
    }
}

use foo::*;
use bar::*;

fn main () -> Result<(), std::io::Error> {
    let x = Ok(());
    x.a();
    x.b();
    x
}

@mmastrac
Copy link
Contributor Author

Looks like tokio is taking the path of duplicating the names for extension traits: rust-lang/rust#54156

It might make sense to follow that path and see how rust core handles conflicts.

Copy link
Contributor

@yoshuawuyts yoshuawuyts left a comment

Choose a reason for hiding this comment

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

💯

@yoshuawuyts yoshuawuyts merged commit af9669a into async-rs:master Jun 6, 2019
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