-
Notifications
You must be signed in to change notification settings - Fork 59
Get rid of where Self: std::marker::Sized
#45
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
Comments
Also, with the current approach, I can't call
|
I've posted this question to StackOverlfow. https://stackoverflow.com/questions/64975080/invoking-a-method-on-a-trait-object |
This issue is just the worst... It keeps coming back in all kinds of situations - the I see no other option than to drastically change the |
I've tried changing the For example, when creating a new With the refactor I suggested above, I explicitly pass |
Just tried adding |
However, when I try to do this while keeping a reference to pub struct Resource<'a> {
propvals: PropVals,
subject: String,
classes: Option<Vec<Class>>,
// `impl Trait` not allowed outside of function and inherent method return types rustcE0562
store: &'a impl Storelike,
commit: CommitBuilder,
} One possible solution to this, was to use Generics. Just tried that, but I also fail to get that working. |
I kind of fixed it, but it still doesn't feel right. I set a Anyway - I can now do all the things i needed to do. Use |
Well, it turns out setting :Sized also comes with some serious limitations. I'm working on a plugin #73 system, which includes structs that contain functions that refer to I think there are two solutions to this:
|
I'm still learning Rust, and that means that I'm still not fully understanding traits and object safety.
We have a
Store
struct based on theStorelike
trait, which contains all the data. We also haveResource
, which have a reference to aStorelike
.This enables a more convenient API, so we can have:
instead of requiring the store in every single call:
Since our Store is a trait, it's size is not known at compile time. From what I understand, this means that in methods on the Storelike trait where we create Resources, we need to explicitly state that the Store (Self) is Sized:
This
where
clause is now needed in all functions that create resources, and I feel like that is wrong, although I can't say for sure that it is.I thought it might make sense to require
Sized
in theStorelike
trait, like this:pub trait Storelike: Sized
, and although that removes the need for the where clauses, it introduces another problem. In every signature where a reference to the store is made:...this error appears:
The text was updated successfully, but these errors were encountered: