impl_trait

Crates.ioimpl_trait
lib.rsimpl_trait
version0.1.7
sourcesrc
created_at2021-03-22 23:57:35.64119
updated_at2021-08-16 17:02:25.197695
descriptionAllows impl trait inside inherent impl.
homepage
repositoryhttps://soniex2.autistic.space/git-repos/impl_trait.git
max_upload_size
id372340
size60,878
Soni L. (SoniEx2)

documentation

README

impl_trait!

TL;DR: this adds impl_trait! which lets you do:

struct Foo;

trait Bar {}

impl_trait! {
  /// Yes, you can write docs here.
  impl Foo {
    /// You can write docs here too.
    fn as_dyn_bar(&self) -> &dyn Bar {
      self
    }
    /// You can even write docs here!
    impl trait Bar {
    }
  }
}

A few things to note:

  • You can have generics on the main impl<T> Foo block.
  • You can have generics on the trait impl with impl trait<T> Bar.
  • We unfortunately cannot make rustdoc output the trait impls as if they were somehow "inherent" to the type. They'll still show up in a separate "trait impls" section rather than as part of the appropriate impl block.

A note on licensing

This is a proc macro. It basically implements a simple syntax sugar that you can trivially desugar by hand.

In fact, it's probably easier to desugar by hand than to write a dang proc macro to do it for you!

Nevertheless, yes, this is AGPLv3-licensed. It's the most restrictive open source license available. If you don't like it, just abolish copyright y'know?

Thankfully, the AGPLv3 comes with plenty of holes like the system library exception, as well as the fact that clause 13 specifically starts with the words "if you modify the Program" i.e. it explicitly doesn't apply if you're just using the plain old crates.io version of this crate.

Further, this code is awful, so please don't copy it.

License

impl_trait - Rust proc macro that significantly reduces boilerplate
Copyright (C) 2021  Soni L.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.
Commit count: 0

cargo fmt