Skip to content

Is it possible to parameterize traits over self mode? #7918

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

Closed
bblum opened this issue Jul 19, 2013 · 2 comments
Closed

Is it possible to parameterize traits over self mode? #7918

bblum opened this issue Jul 19, 2013 · 2 comments
Labels
A-trait-system Area: Trait system

Comments

@bblum
Copy link
Contributor

bblum commented Jul 19, 2013

I have no idea if this is theoretically easy or impossible or what. But consider this trait from my design for select:

trait SelectPort<T> {
    fn recv_ready(self) -> Option<T>;
}

This takes self by value because for a oneshot port, it has to consume the endpoint. But for a stream port, you might not be allowed to have it by value at all, but still expect to be able to select on it. It would be nice to have:

trait SelectPort<T, selfmode> {
    fn recv_ready(selfmode) -> Option<T>;
}

and then:

impl <T> SelectPort<T, self> for PortOne<T> ...
impl <T> SelectPort<T, &mut self> for Port<T> ...
@alexcrichton
Copy link
Member

Couldn't this already be implemented with something like

trait SelectPort<T> {
    fn recv_ready(self) -> Option<T>;
}

impl <T> SelectPort<T> for PortOne<T> {
  ...
}
impl <'self, T> SelectPort<T> for &'self mut Port<T> {
  ...
}

In the second one you're not really consuming self?

@bblum
Copy link
Contributor Author

bblum commented Jul 20, 2013

Good point. I should do that.

@bblum bblum closed this as completed Jul 20, 2013
flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 4, 2021
Use .cargo/config.toml instead of .cargo/config

`.cargo/config.toml` is the preferred form for the local configuration file. This is emphasized in _The Cargo Book_ with the following note:

> Note: Cargo also reads config files without the `.toml` extension, such as `.cargo/config`. Support for the `.toml` extension was added in version 1.39 and is the preferred form.

Moreover, this helps with toml-aware text editors as they will recognize the file extension.

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system
Projects
None yet
Development

No branches or pull requests

2 participants