Giter Site home page Giter Site logo

Comments (3)

clux avatar clux commented on May 31, 2024

Ahh, wtf. You can put dashes in key names there!

Thank you. Yeah, we should do some handling here.

We could do either:

  • serde(rename) attr on members with illegal characters
  • rawstring keys like we do for keywords EDIT: won't work.

and it won't clash with future initiatives for solving #22

We will have to inject serde rename annotations on the members in:

kopium/src/main.rs

Lines 181 to 192 in b309292

for m in s.members {
self.print_docstr(m.docs, " ");
if let Some(annot) = m.field_annot {
println!(" {}", annot);
}
let safe_name = if KEYWORDS.contains(&m.name.as_ref()) {
format_ident!("r#{}", m.name)
} else {
format_ident!("{}", m.name)
};
let spec_trimmed_type = m.type_.as_str().replace(&format!("{}Spec", kind), &kind);
println!(" pub {}: {},", safe_name, spec_trimmed_type);

EDIT: marking as good first issue. Can use the linked CRD in issue as a test case and extend the test suite (see justfile) to verify the generated variant can compile.

from kopium.

jcaesar avatar jcaesar commented on May 31, 2024

Rawstrings won't do the trick:

struct Foo {
    r#-XX: (),
}
error: found invalid character; only `#` is allowed in raw string delimitation: -
 --> src/lib.rs:2:5
  |
2 |     r#-XX: (),
  |     ^^^

error: could not compile `playground` due to previous error

from kopium.

clux avatar clux commented on May 31, 2024

Damnit. Yep :(
Updating. Guess we have to do special case serde renames for them.

from kopium.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.