You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use dynomite::Item;use std::marker::PhantomData;#[derive(Item,Clone)]structBook{#[dynomite(partition_key)]pubpartition_key:Id<Self>,pubname:String,}traitMyTrait{}implMyTraitforBook{}#[derive(PartialOrd,PartialEq,Clone,Debug)]structId<T:MyTrait>(String,PhantomData<T>);impl<T:MyTrait> dynomite::AttributeforId<T>{fninto_attr(self:Self) -> dynomite::dynamodb::AttributeValue{todo!()}fnfrom_attr(value: dynomite::dynamodb::AttributeValue) -> Result<Self, dynomite::AttributeError>{todo!()}}
but this code gives the following error:
Log
~/junk/rust-sandbox $ cargo check -p crate_foo
Checking crate_foo v0.1.0 (/home/veetaha/junk/rust-sandbox/crate_foo)
error[E0277]: the trait bound `BookKey: MyTrait` is not satisfied
--> crate_foo/src/main.rs:7:5
|
7 | pub partition_key: Id<Self>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MyTrait` is not implemented for `BookKey`
...
15 | struct Id<T: MyTrait>(String, PhantomData<T>);
| ------- required by this bound in `Id`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
error: could not compile `crate_foo`.
To learn more, run the command again with --verbose.
~/junk/rust-sandbox $
It looks like Id<Self> is copied into struct BookKey { ... } body but instead we should replace all Self occurences with the struct #[derive(Item)] is placed onto before copying it into BookKey.
🤔 Expected Behavior
This should work out of the box without compile errors.
The workaround is to use Book literally instead of Self
It looks like Id is copied into struct BookKey { ... } body but instead we should replace all Self occurences with the struct #[derive(Item)] is placed onto before copying it into BookKey.
I need to parse this problem a bit. This sounds a bit like an edge case to me. I'm the majority of cases when you declare a field is a partition key the item key struct simply represents a copy of that field.
At the macro level there isn't really type information only syntax and I'm not sure how I would be able to infer something like this from syntax alone.
🐛 Bug description
Given this code:
but this code gives the following error:
Log
It looks like
Id<Self>
is copied intostruct BookKey { ... }
body but instead we should replace allSelf
occurences with the struct#[derive(Item)]
is placed onto before copying it intoBookKey
.🤔 Expected Behavior
This should work out of the box without compile errors.
The workaround is to use
Book
literally instead ofSelf
🌍 Your environment
dynomite version:
0.8.2
rustc version:
rustc 1.44.1 (c7087fe00 2020-06-17)
The text was updated successfully, but these errors were encountered: