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

Support conversion from &String to Slice #11

Merged
merged 3 commits into from
Dec 4, 2024

Conversation

carlsverre
Copy link
Contributor

related to fjall-rs/fjall#99

@marvin-j97 marvin-j97 added the enhancement New feature or request label Dec 4, 2024
@marvin-j97
Copy link
Contributor

marvin-j97 commented Dec 4, 2024

I thought Rust would use the From<&str>, because when you have:

fn f(s: &str) {}

let a = String::new();
f(&a); // this works

But apparently not

Edit: Yeah, this needs a manual deref:

struct ByteView(String);

impl From<&str> for ByteView {
    fn from(value: &str) -> Self {
        Self(value.into())
    }
}

fn f<T: Into<ByteView>>(v: T) {
    let bv = v.into();
}

pub fn main() {
    let a = String::new();
    f(&*a); // only this works
}

@carlsverre
Copy link
Contributor Author

Yea, unfortunately it doesn't seem to trigger the implicit deref for From impls.

@marvin-j97 marvin-j97 merged commit 057c195 into fjall-rs:main Dec 4, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants