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

Generate Display impl for enums #643

Merged
merged 1 commit into from Nov 16, 2018

Conversation

Projects
None yet
3 participants
@GuillaumeGomez
Member

GuillaumeGomez commented Oct 9, 2018

Part of #448.

I have still troubles to fully understand how to correctly do it for flags but it'll come as well.

cc @EPashkin @sdroege

Show resolved Hide resolved src/codegen/enums.rs Outdated
@@ -65,6 +65,7 @@ pub fn generate(env: &Env, root_path: &Path, mod_rs: &mut Vec<String>) {
file_saver::save_to_file(path, env.config.make_backup, |w| {
try!(general::start_comments(w, &env.config));
try!(general::uses(w, env, &imports));
try!(writeln!(w, "use std::fmt;"));

This comment has been minimized.

@EPashkin

EPashkin Oct 10, 2018

Member

This better be done with imports.add

@EPashkin

This comment has been minimized.

Member

EPashkin commented Oct 10, 2018

@GuillaumeGomez Thanks, 👍

for member in &members {
try!(cfg_deprecated(w, env, member.deprecated_version, false, 3));
try!(version_condition(w, env, member.version, false, 3));
try!(writeln!(w, "\t\t\t{0}::{1} => \"{1}\",", enum_.name, member.name));

This comment has been minimized.

@sdroege

sdroege Oct 10, 2018

Member

Two issues here

  1. It should be configurable if this generated, just like what I added for other types. So that it can be manually overridden.
  2. Use the "special functions" stuff from gir (just like we do for the various trait impls of other kinds of types). If there's e.g. a to_string() function, then this can be used here. I actually only thought (in the issue I created months ago) about creating the Display impl only if there's a special function for it.

This comment has been minimized.

@EPashkin

EPashkin Oct 10, 2018

Member

Note: currently we don't generate enums and flags functions, so this need be done before, if we decide generate only for some enums.

This comment has been minimized.

@sdroege

sdroege Oct 10, 2018

Member

That should happen because otherwise this is going to break the GStreamer bindings (where I have some custom Display impls) :)

@GuillaumeGomez GuillaumeGomez force-pushed the GuillaumeGomez:enum-display branch from d9728d1 to 1b3fb36 Nov 15, 2018

@GuillaumeGomez

This comment has been minimized.

Member

GuillaumeGomez commented Nov 15, 2018

Updated.

@EPashkin

Thanks. Now we can skip generation if needed.

Show resolved Hide resolved src/codegen/enums.rs Outdated
Show resolved Hide resolved src/codegen/enums.rs Outdated
Show resolved Hide resolved src/codegen/object.rs Outdated
Show resolved Hide resolved src/codegen/object.rs Outdated

@GuillaumeGomez GuillaumeGomez force-pushed the GuillaumeGomez:enum-display branch from 374c7d0 to f4ed576 Nov 15, 2018

@GuillaumeGomez

This comment has been minimized.

Member

GuillaumeGomez commented Nov 15, 2018

Updated.

@GuillaumeGomez GuillaumeGomez force-pushed the GuillaumeGomez:enum-display branch from f4ed576 to 810910a Nov 15, 2018

@EPashkin

This comment has been minimized.

Member

EPashkin commented Nov 15, 2018

@GuillaumeGomez Thanks. Waiting CI and @sdroege confirmation

@sdroege

This comment has been minimized.

Member

sdroege commented Nov 16, 2018

Seems fine to me

@EPashkin EPashkin merged commit 1b7c3da into gtk-rs:master Nov 16, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@GuillaumeGomez GuillaumeGomez deleted the GuillaumeGomez:enum-display branch Nov 16, 2018

let generate_display_trait = toml_object
.lookup("generate_display_trait")
.and_then(|v| v.as_bool())
.unwrap_or(true);

This comment has been minimized.

@sdroege

sdroege Nov 18, 2018

Member

@GuillaumeGomez Why does this default to true still?

This comment has been minimized.

@GuillaumeGomez

GuillaumeGomez Nov 18, 2018

Member

By "default" we want to generate the Display trait. However, if we have an invalid value, would you prefer instead?

This comment has been minimized.

@sdroege

sdroege Nov 18, 2018

Member

I would prefer for it to be opt-in

This comment has been minimized.

@GuillaumeGomez

GuillaumeGomez Nov 18, 2018

Member

@EPashkin opened #668. You might want to take a look at it. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment