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

Implement as_ref for overloads in cxx-qt-lib #901

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Montel
Copy link
Contributor

@Montel Montel commented Mar 20, 2024

Closed: #810

@Montel Montel self-assigned this Mar 20, 2024
@Montel
Copy link
Contributor Author

Montel commented Mar 20, 2024

error[E0308]: mismatched types
--> crates/cxx-qt-lib/src/gui/qpen.rs:186:9
|
184 | fn as_ref(&self) -> &ffi::QPen {
| ---------- expected &qpen::QPen because of return type
185 | let pen = ffi::qpen_init_from_qcolor(&self);
186 | pen
| ^^^ expected &QPen, found QPen
|
help: consider borrowing here
|
186 | &pen
| +

For more information about this error, try rustc --explain E0308.
The following warnings were emitted during compilation:

but if I use &pen if doesn't compile too.

Do you have an idea ?
thanks

@Montel
Copy link
Contributor Author

Montel commented Mar 20, 2024

warning: [email protected]: Compiler version doesn't include clang or GCC: "c++" "--version"
error[E0515]: cannot return reference to local variable pen
--> crates/cxx-qt-lib/src/gui/qpen.rs:186:9
|
186 | &pen
| ^^^^ returns a reference to data owned by the current function

For more information about this error, try rustc --explain E0515.
The following warnings were emitted during compilation:

@ahayzen-kdab
Copy link
Collaborator

Fun :-) so because it wants a reference the lifetime is the fun part here. Either we would need to link up the lifetimes somehow (not sure if possible?) or maybe we'd need to go the Into route instead as that could be a value not a reference, eg accept Into<QPen> we also need to see what is the common way of doing this in the Rust ecosystem, so looking for examples in std would be good.

@ahayzen-kdab
Copy link
Collaborator

Also note that From<T> is usually preferred over Into<T>

@Montel
Copy link
Contributor Author

Montel commented Apr 5, 2024

@LeonMatthesKDAB do you have an idea how to fix it ? :)

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.

For overloads in cxx-qt-lib use impl AsRef
2 participants