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

Impl From<QString>, From<QByteArray> for Vec<u8> #261

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Ayush1325
Copy link
Collaborator

I basically needed implementation of Into<Vec<u8>> so that I can construct CString::new() from QString.

I am not sure whether this is the best way to achieve this so I would like someone else's input on this.

Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AsRef<CStr> makes sense. But i'm a bit torn about the other conversion, because they are quite expensive allocation that can, be done otherwise with the existing API.

@@ -317,6 +317,12 @@ impl TryFrom<QString> for i16 {
}
}

impl From<QString> for Vec<u8> {
fn from(x: QString) -> Self {
QByteArray::from(x).into()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First you convert from QString to QByteArray, and then again to to Vec, that's two allocation.
You'd be better of using Rust's DecodeUtf16
(or passing through String instead)

@Ayush1325 Ayush1325 marked this pull request as draft March 13, 2022 20:52
@Ayush1325
Copy link
Collaborator Author

I see, I will check out a better way to achieve this.

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