Skip to content

Conversation

@soareschen
Copy link
Collaborator

@soareschen soareschen commented Jan 31, 2026

This PR brings a quality of life improvement on the use of #[cgp_impl], by allowing the generic Context type to be omitted.

Example

Before this PR, the generic Context needs to be always specified, such as:

#[cgp_impl(GreetHello)]
impl<Context> Greeter for Context
where
    Context: HasName,
{
    fn greet(&self) {
        println!("Hello, {}!", self.name());
    }
}

With the changes in this PR, the same provider can now be simplified as:

#[cgp_impl(GreetHello)]
impl Greeter
where
    Self: HasName,
{
    fn greet(&self) {
        println!("Hello, {}!", self.name());
    }
}

This significantly improves the ergonomic of writing context-generic implementations in the simple cases. With the generic Context type removed, a #[cgp_impl] block looks much more like a direct implementation of a trait with no generic parameters involved. This can bridge the gap for developers coming from OOP background, as they can view the implementation as being similar to implementing a class.

@soareschen soareschen merged commit f970c27 into main Jan 31, 2026
5 checks passed
@soareschen soareschen deleted the implicit-context branch January 31, 2026 17:23
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