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

Minor cleanup to use is_some_and(...) instead of map_or(false, ...) #1584

Merged
merged 1 commit into from
Jun 19, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/analysis/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Info {
.trim_end_matches('_')
.rsplit('_')
.next()
.map_or(false, |i| i.parse::<special_functions::Type>().is_ok())
.is_some_and(|i| i.parse::<special_functions::Type>().is_ok())
}

// returns whether the method can be linked in the docs
Expand Down
10 changes: 6 additions & 4 deletions src/analysis/special_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,11 @@ pub fn extract(functions: &mut [FuncInfo], parent_type: &LibType, obj: &GObject)

for (pos, func) in functions.iter_mut().enumerate() {
if is_stringify(func, parent_type, obj) {
let return_transfer_none = func.ret.parameter.as_ref().map_or(false, |ret| {
ret.lib_par.transfer == crate::library::Transfer::None
});
let return_transfer_none = func
.ret
.parameter
.as_ref()
.is_some_and(|ret| ret.lib_par.transfer == crate::library::Transfer::None);

// Assume only enumerations and bitfields can return static strings
let returns_static_ref = return_transfer_none
Expand Down Expand Up @@ -198,7 +200,7 @@ pub fn extract(functions: &mut [FuncInfo], parent_type: &LibType, obj: &GObject)
.parameters
.c_parameters
.first()
.map_or(false, |p| p.ref_mode == super::ref_mode::RefMode::ByRefMut);
.is_some_and(|p| p.ref_mode == super::ref_mode::RefMode::ByRefMut);

specials.traits.insert(
type_,
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn generate(env: &Env, root_path: &Path, mod_rs: &mut Vec<String>) {
.objects
.values()
.filter(|c| {
c.status.need_generate() && c.type_id.map_or(false, |tid| tid.ns_id == namespaces::MAIN)
c.status.need_generate() && c.type_id.is_some_and(|tid| tid.ns_id == namespaces::MAIN)
})
.collect();
let mut has_any = false;
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/doc/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ fn find_method_or_function_by_ctype(
|r| c_type.map_or(true, |t| r.type_(&env.library).c_type == t),
|r| c_type.map_or(true, |t| r.type_(&env.library).c_type == t),
|r| c_type.map_or(true, |t| r.type_(&env.library).c_type == t),
c_type.map_or(false, |t| t.ends_with("Class")),
c_type.is_some_and(|t| t.ends_with("Class")),
false,
)
}
Expand Down
9 changes: 4 additions & 5 deletions src/codegen/doc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ fn generate_doc(w: &mut dyn Write, env: &Env) -> Result<()> {
.map(|analyzed_f| analyzed_f.doc_ignore_parameters.clone())
.unwrap_or_default();

let should_be_documented =
f_info.map_or(false, |f| f.should_docs_be_generated(env));
let should_be_documented = f_info.is_some_and(|f| f.should_docs_be_generated(env));
if !should_be_documented {
continue;
}
Expand Down Expand Up @@ -512,7 +511,7 @@ fn create_object_doc(w: &mut dyn Write, env: &Env, info: &analysis::object::Info
};
if let Some(c_identifier) = &function.c_identifier {
let f_info = info.functions.iter().find(|f| &f.glib_name == c_identifier);
let should_be_documented = f_info.map_or(false, |f| f.should_docs_be_generated(env));
let should_be_documented = f_info.is_some_and(|f| f.should_docs_be_generated(env));

if !should_be_documented {
continue;
Expand Down Expand Up @@ -587,7 +586,7 @@ fn create_object_doc(w: &mut dyn Write, env: &Env, info: &analysis::object::Info
.virtual_methods
.iter()
.find(|f| &f.glib_name == c_identifier);
let should_be_documented = f_info.map_or(false, |f| f.should_docs_be_generated(env));
let should_be_documented = f_info.is_some_and(|f| f.should_docs_be_generated(env));
if !should_be_documented {
continue;
}
Expand Down Expand Up @@ -695,7 +694,7 @@ fn create_record_doc(w: &mut dyn Write, env: &Env, info: &analysis::record::Info
};
if let Some(c_identifier) = &function.c_identifier {
let f_info = info.functions.iter().find(|f| &f.glib_name == c_identifier);
let should_be_documented = f_info.map_or(false, |f| f.should_docs_be_generated(env));
let should_be_documented = f_info.is_some_and(|f| f.should_docs_be_generated(env));
if !should_be_documented {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ pub fn bounds(
let skip_lifetimes = bounds
.iter()
// TODO: False or true?
.filter(|bound| bound.alias.map_or(false, |alias| skip.contains(&alias)))
.filter(|bound| bound.alias.is_some_and(|alias| skip.contains(&alias)))
.filter_map(|bound| match bound.bound_type {
IsA(lifetime) | AsRef(lifetime) => lifetime,
_ => None,
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ pub fn declare_default_from_new(
&& f.status.need_generate()
&& f.name == "new"
// Cannot generate Default implementation for Option<>
&& f.ret.parameter.as_ref().map_or(false, |x| !*x.lib_par.nullable)
&& f.ret.parameter.as_ref().is_some_and(|x| !*x.lib_par.nullable)
}) {
if func.parameters.rust_parameters.is_empty() {
writeln!(w)?;
Expand Down
2 changes: 1 addition & 1 deletion src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ impl Library {
.config
.objects
.get(&full_name)
.map_or(false, |obj| obj.generate_builder)
.is_some_and(|obj| obj.generate_builder)
&& properties
.iter()
.any(|prop| prop.construct_only || prop.construct || prop.writable)
Expand Down
6 changes: 3 additions & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl Library {
let get_type = elem.attr_required("get-type")?;
let version = self.read_version(parser, ns_id, elem)?;
let deprecated_version = self.read_deprecated_version(parser, ns_id, elem)?;
let is_fundamental = elem.attr("fundamental").map_or(false, |x| x == "1");
let is_fundamental = elem.attr("fundamental").is_some_and(|x| x == "1");
let (ref_fn, unref_fn) = if is_fundamental {
(
elem.attr("ref-func").map(ToOwned::to_owned),
Expand All @@ -172,8 +172,8 @@ impl Library {
(None, None)
};

let is_abstract = elem.attr("abstract").map_or(false, |x| x == "1");
let final_type = elem.attr("final").map_or(false, |x| x == "1");
let is_abstract = elem.attr("abstract").is_some_and(|x| x == "1");
let final_type = elem.attr("final").is_some_and(|x| x == "1");

let mut fns = Vec::new();
let mut signals = Vec::new();
Expand Down
Loading