MCPcopy Index your code
hub / github.com/auto-impl-rs/auto_impl

github.com/auto-impl-rs/auto_impl @v1.3.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.3.0 ↗ · + Follow
245 symbols 300 edges 73 files 21 documented · 9%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

auto_impl CI Crates.io docs

A proc-macro attribute for automatically implementing a trait for references, some common smart pointers and closures.

Usage

This library requires Rust 1.56.0 or newer. This library doesn't leave any public API in your code.

Add auto_impl to your Cargo.toml and just use it in your crate:

// In Rust 2015 you still need `extern crate auto_impl;` at your crate root
use auto_impl::auto_impl;

Add an auto_impl attribute to traits you want to automatically implement for wrapper types. Here is a small example:

// This will generate two additional impl blocks: one for `&T` and one
// for `Box<T>` where `T: Foo`.
#[auto_impl(&, Box)]
trait Foo {
    fn foo(&self);
}

impl Foo for i32 {
    fn foo(&self) {}
}

fn requires_foo(_: impl Foo) {}


requires_foo(0i32);  // works: through the impl we defined above
requires_foo(&0i32); // works: through the generated impl
requires_foo(Box::new(0i32)); // works: through the generated impl

For more explanations, please see the documentation and for more examples, see the examples folder.

Alternatives

This library implements a fraction of a very broad and complex usecase. It's mostly useful for applications that define traits for components, and want to be able to abstract over the storage for those traits. If it doesn't offer some functionality you need, check out the impl-tools project.


License

Licensed under either of

  • Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Extension points exported contracts — how you extend this code

Foo (Interface)
Shows the error message for the case that `#[auto_impl]` was used with incorrect proxy types. Only proxy types like `&`
examples/error_messages.rs
Trait (Interface)
(no doc) [1 implementers]
tests/compile-pass/trait_obj_default_method.rs
Foo (Interface)
(no doc) [1 implementers]
tests/compile-fail/attr_on_impl_block.rs
DisplayCollection (Interface)
(no doc) [1 implementers]
examples/refs.rs
Foo (Interface)
(no doc) [1 implementers]
examples/keep_default_for.rs
Component (Interface)
(no doc) [1 implementers]
examples/async_await/src/main.rs
Test (Interface)
(no doc)
tests/no_std.rs
AsyncTrait (Interface)
(no doc)
tests/since_1.75/compile-pass/async_trait.rs

Core symbols most depended-on inside this repo

show_first
called by 5
examples/refs.rs
param_span
called by 4
src/analyze.rs
should_keep_default_for
called by 3
src/gen.rs
filter_attrs
called by 3
src/gen.rs
is_fn
called by 3
src/proxy.rs
foo
called by 3
tests/compile-pass/value_self_for_fn_once.rs
is_our_attr
called by 2
src/attr.rs
parse_types
called by 2
src/proxy.rs

Shape

Function 116
Interface 76
Method 26
Class 23
Enum 4

Languages

Rust100%

Modules by API surface

src/gen.rs14 symbols
examples/names.rs10 symbols
tests/no_std.rs8 symbols
tests/compile-pass/self_bound_multiple.rs7 symbols
src/analyze.rs7 symbols
tests/compile-pass/trait_obj_default_method.rs6 symbols
tests/compile-pass/self_bound_default_method.rs6 symbols
src/attr.rs6 symbols
examples/keep_default_for.rs6 symbols
tests/compile-pass/self_bound.rs5 symbols
tests/compile-fail/super_trait_not_implemented.rs5 symbols
examples/async_await/src/main.rs5 symbols

For agents

$ claude mcp add auto_impl \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact