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

chore: fix caching issue for conditional merchant creation #68

Merged
merged 3 commits into from Feb 5, 2024

Conversation

NishantJoshi00
Copy link
Member

Description

There is an issue with the consistency of nested types for caching, the issue lies in the way Deref works and how the traits are implemented.

example:

struct A;
struct B;
struct C;

trait MyTrait {}

impl MyTrait for C {}

impl Deref for A {
	type Target = B;
}
impl Deref for B {
	type Target = C;
}

fn handle<X, Y>(data: X)
where
	X: Deref<Target = Y>,
	Y: MyTrait
{}

In this scenerio struct of type B can be passed to the function handle without any issue, but when trying to pass A you will get an error:

error[E0277]: the trait bound `B: MyTrait` is not satisfied
   --> src/main.rs:112:5
    |
112 |     handle(A);
    |     ^^^^^^ the trait `MyTrait` is not implemented for `B`
    |
    = help: the trait `MyTrait` is implemented for `C`
note: required by a bound in `handle`
   --> src/main.rs:108:5
    |
105 | fn handle<X, Y>(_data: X)
    |    ------ required by a bound in this function
...
108 |     Y: MyTrait
    |        ^^^^^^^ required by this bound in `handle`

This example describes the situation with caching, where as the intermediate layers are only implementing Deref for the internal Storage, and does not auto implement the traits that are implemented on Storage. This issue will be mitigated once rust stabalizes specialization.

Tracking issue for specialization: rust-lang/rust#31844

ShankarSinghC
ShankarSinghC previously approved these changes Feb 5, 2024
@NishantJoshi00 NishantJoshi00 merged commit 258b3ac into main Feb 5, 2024
3 checks passed
@NishantJoshi00 NishantJoshi00 deleted the fix-merchant-cache branch February 5, 2024 09:34
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.

None yet

3 participants