From 00d10b14f7a5038e2fd4412752df37a2f6fb33c3 Mon Sep 17 00:00:00 2001 From: Evgenii Pashkin Date: Sun, 18 Nov 2018 22:11:41 +0300 Subject: [PATCH] Default generate_display_trait --- README.md | 8 ++++++-- src/config/config.rs | 9 ++++++++- src/config/gobjects.rs | 16 ++++++++++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 92f3ea520..e5d071f1a 100644 --- a/README.md +++ b/README.md @@ -107,10 +107,14 @@ target_path = "." work_mode = "normal" generate_safety_asserts = true deprecate_by_min_version = true -# with this option enabled, versions for gir and gir-files saved only to one file to minimize noise, +# With this option enabled, versions for gir and gir-files saved only to one file to minimize noise, # can also take path to the directory for saving "versions.txt" or filename with extension. # Relative to target_path single_version_file = true +# Generation of Display trait enabled for all enums, classes, etc., +# which do not have an override for `generate_display_trait` +# (defaults to "true") +generate_display_trait = true ``` This mode generates only the specified objects. You can either add the object's fullname to the `generate` array or add it to the `manual` array (but in this case, it won't be generated, just used in other functions/methods instead of generating an "ignored" argument). Example: @@ -140,7 +144,7 @@ module_name = "soome_class" version = "3.12" # prefixed object in mod.rs with #[cfg(mycond)] cfg_condition = "mycond" -# if you want to write your own Display implementation, you can disable gir automatic generation +# if you want to override default option Ex. for write your own Display implementation generate_display_trait = false # define overrides for function [[object.function]] diff --git a/src/config/config.rs b/src/config/config.rs index 5e815fc3c..db9553e7b 100644 --- a/src/config/config.rs +++ b/src/config/config.rs @@ -33,6 +33,7 @@ pub struct Config { pub show_statistics: bool, pub concurrency: library::Concurrency, pub single_version_file: Option, + pub generate_display_trait: bool, } impl Config { @@ -128,10 +129,15 @@ impl Config { None => Default::default(), }; + let generate_display_trait = match toml.lookup("options.generate_display_trait") { + Some(v) => try!(v.as_result_bool("options.generate_display_trait")), + None => true, + }; + // options.concurrency is the default of all objects if nothing // else is configured let mut objects = toml.lookup("object") - .map(|t| gobjects::parse_toml(t, concurrency)) + .map(|t| gobjects::parse_toml(t, concurrency, generate_display_trait)) .unwrap_or_default(); gobjects::parse_status_shorthands(&mut objects, &toml, concurrency); @@ -182,6 +188,7 @@ impl Config { show_statistics: show_statistics.into().unwrap_or(false), concurrency, single_version_file, + generate_display_trait, }) } diff --git a/src/config/gobjects.rs b/src/config/gobjects.rs index 35110fd0a..4a82cb0d3 100644 --- a/src/config/gobjects.rs +++ b/src/config/gobjects.rs @@ -112,10 +112,14 @@ impl Default for GObject { //TODO: ?change to HashMap pub type GObjects = BTreeMap; -pub fn parse_toml(toml_objects: &Value, concurrency: library::Concurrency) -> GObjects { +pub fn parse_toml( + toml_objects: &Value, + concurrency: library::Concurrency, + generate_display_trait: bool, +) -> GObjects { let mut objects = GObjects::new(); for toml_object in toml_objects.as_array().unwrap() { - let gobject = parse_object(toml_object, concurrency); + let gobject = parse_object(toml_object, concurrency, generate_display_trait); objects.insert(gobject.name.clone(), gobject); } objects @@ -147,7 +151,11 @@ fn conversion_type_from_str(conversion_type: &str) -> Option GObject { +fn parse_object( + toml_object: &Value, + concurrency: library::Concurrency, + default_generate_display_trait: bool, +) -> GObject { let name: String = toml_object .lookup("name") .expect("Object name not defined") @@ -256,7 +264,7 @@ fn parse_object(toml_object: &Value, concurrency: library::Concurrency) -> GObje let generate_display_trait = toml_object .lookup("generate_display_trait") .and_then(|v| v.as_bool()) - .unwrap_or(true); + .unwrap_or(default_generate_display_trait); if status != GStatus::Manual && ref_mode.is_some() { warn!("ref_mode configuration used for non-manual object {}", name);