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

corrected find_enum and find_message for keyword identifiers #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

awestlake87
Copy link

No description provided.

@tafia
Copy link
Owner

tafia commented Oct 10, 2017

First thanks for the PR and sorry for answering this late.

Can you please give more context why it is needed. Could you add a broken test for instance?
As for your fn here is a rustier version of if, (could be enhanced but performance of codegen is really not critical.

pub fn get_ident(ident: &str) -> String { // `&String` is usually replaced with more generic `&str` which both point to the same data
    if !ident.contains('.') {
        if RUST_KEYWORDS.contains(&ident) {
            format!("{}_pb", ident) // this will create a new `String`, probably without new allocation
        }
        else {
            ident.clone()
        }
    }
    else {
        ident.split('.').map(|s| get_ident(s)).collect::<Vec<_>>().join(".") // not pretty but ok!, note that i could remove the `to_string` because I changed the signature to work with `&str`
    }
}

@awestlake87
Copy link
Author

Oh, yeah my bad. I made issue #75 when I made the pull request, but i forgot to link 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.

2 participants