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

Default generate_display_trait #668

Merged
merged 1 commit into from Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Expand Up @@ -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:
Expand Down Expand Up @@ -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]]
Expand Down
9 changes: 8 additions & 1 deletion src/config/config.rs
Expand Up @@ -33,6 +33,7 @@ pub struct Config {
pub show_statistics: bool,
pub concurrency: library::Concurrency,
pub single_version_file: Option<PathBuf>,
pub generate_display_trait: bool,
}

impl Config {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -182,6 +188,7 @@ impl Config {
show_statistics: show_statistics.into().unwrap_or(false),
concurrency,
single_version_file,
generate_display_trait,
})
}

Expand Down
16 changes: 12 additions & 4 deletions src/config/gobjects.rs
Expand Up @@ -112,10 +112,14 @@ impl Default for GObject {
//TODO: ?change to HashMap<String, GStatus>
pub type GObjects = BTreeMap<String, GObject>;

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
Expand Down Expand Up @@ -147,7 +151,11 @@ fn conversion_type_from_str(conversion_type: &str) -> Option<conversion_type::Co
}
}

fn parse_object(toml_object: &Value, concurrency: library::Concurrency) -> 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")
Expand Down Expand Up @@ -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);
Expand Down