Skip to content

Commit b2baa35

Browse files
committed
Cleanup
1 parent 6c4981c commit b2baa35

File tree

16 files changed

+40
-42
lines changed

16 files changed

+40
-42
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ readme = "README.md"
77
keywords = ["opencv", "vision"]
88
license = "MIT"
99
version = "0.94.2"
10+
# bump edition to 2024 when MSRV is 1.85
1011
edition = "2021"
1112
rust-version = "1.77.0"
1213
authors = ["Pro <twisted.fall@gmail.com>", "Mathieu Poumeyrol <kali@zoy.org>"]
@@ -28,7 +29,7 @@ libc = "0.2"
2829
num-traits = "0.2"
2930
once_cell = "1"
3031
# version 0.8.20 doesn't contain the deficiency mentioned in https://deps.rs/crate/opencv/0.59.0#vulnerabilities
31-
rgb = { version = "0.8.20", features = ["argb"], optional = true }
32+
rgb = { version = "0.8.20", default-features = false, features = ["argb"], optional = true }
3233

3334
[target.'cfg(target_os = "windows")'.dependencies]
3435
windows = { version = "0.61", features = ["Win32_Graphics_Direct3D9", "Win32_Graphics_Direct3D10", "Win32_Graphics_Direct3D11"] }

binding-generator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ regex = "1"
2121
shlex = { version = "1.3", default-features = false }
2222

2323
[dev-dependencies]
24-
tempfile = "3"
24+
tempfile = { version = "3", default-features = false }
2525

2626
[features]
2727
clang-runtime = ["clang/runtime", "clang-sys/runtime"]

binding-generator/src/name_pool.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ impl NamePool {
2424
out
2525
}
2626

27-
pub fn into_disambiguator<T, I, CB>(mut self, args: I, mut name_cb: CB) -> impl Iterator<Item = (String, T)>
27+
pub fn into_disambiguator<T, I, CB>(mut self, args: I, name_cb: CB) -> impl Iterator<Item = (String, T)>
2828
where
2929
I: IntoIterator<Item = T>,
30-
CB: for<'a> FnMut(&'a T) -> Cow<'a, str>,
30+
CB: for<'a> Fn(&'a T) -> Cow<'a, str>,
3131
{
32-
args.into_iter().map(move |f| {
33-
let mut name = name_cb(&f);
32+
args.into_iter().map(move |item| {
33+
let mut name = name_cb(&item);
3434
self.make_unique_name(&mut name);
35-
(name.into_owned(), f)
35+
(name.into_owned(), item)
3636
})
3737
}
3838
}

binding-generator/src/writer/rust_native/class/gen.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,7 @@ pub fn extern_functions<'tu, 'ge>(c: &Class<'tu, 'ge>) -> Vec<Func<'tu, 'ge>> {
188188
let mut out = c
189189
.methods(|m| m.exclude_kind().is_included())
190190
.into_iter()
191-
.flat_map(|m| {
192-
let companion_func = m.companion_functions();
193-
iter::once(m).chain(companion_func)
194-
})
191+
.flat_map(|m| m.with_companion_functions())
195192
.collect::<Vec<_>>();
196193

197194
if c.has_implicit_clone() {

binding-generator/src/writer/rust_native/func.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use std::borrow::Cow;
22
use std::collections::HashMap;
33
use std::fmt::Write;
4+
use std::iter;
5+
use std::iter::{Chain, Once};
46
use std::rc::Rc;
7+
use std::vec::IntoIter;
58

69
use once_cell::sync::Lazy;
710
use Cow::{Borrowed, Owned};
@@ -20,6 +23,9 @@ use crate::{reserved_rename, CompiledInterpolation, Element, Func, IteratorExt,
2023

2124
pub trait FuncExt<'tu, 'ge> {
2225
fn companion_functions(&self) -> Vec<Func<'tu, 'ge>>;
26+
fn with_companion_functions(self) -> Chain<Once<Self>, IntoIter<Self>>
27+
where
28+
Self: Sized;
2329
}
2430

2531
impl<'tu, 'ge> FuncExt<'tu, 'ge> for Func<'tu, 'ge> {
@@ -32,6 +38,11 @@ impl<'tu, 'ge> FuncExt<'tu, 'ge> for Func<'tu, 'ge> {
3238
out.extend(companion_func_boxref_mut(self));
3339
out
3440
}
41+
42+
fn with_companion_functions(self) -> Chain<Once<Self>, IntoIter<Self>> {
43+
let companions = self.companion_functions();
44+
iter::once(self).chain(companions)
45+
}
3546
}
3647

3748
impl RustElement for Func<'_, '_> {

binding-generator/src/writer/rust_native/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ impl GeneratorVisitor<'_> for RustNativeBindingWriter<'_> {
136136

137137
fn visit_func(&mut self, func: Func) {
138138
self.emit_debug_log(&func);
139-
let companion_funcs = func.companion_functions();
140-
for func in iter::once(func).chain(companion_funcs) {
139+
for func in func.with_companion_functions() {
141140
let name = func.identifier();
142141
self.rust_funcs.push((name.clone(), func.gen_rust(self.opencv_version)));
143142
self.extern_funcs.push((name.clone(), func.gen_rust_externs()));

binding-generator/src/writer/rust_native/type_ref/render_lane.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,16 @@ pub trait RenderLaneTrait {
3838
"".to_string()
3939
}
4040
fn rust_arg_func_call(&self, name: &str) -> String;
41-
4241
fn rust_arg_post_success_call(&self, _name: &str) -> String {
4342
"".to_string()
4443
}
45-
4644
fn rust_extern_arg_func_decl(&self, name: &str) -> String;
4745

4846
fn cpp_arg_func_decl(&self, name: &str) -> Cow<str>;
49-
5047
fn cpp_arg_pre_call(&self, _name: &str) -> String {
5148
"".to_string()
5249
}
53-
5450
fn cpp_arg_func_call(&self, name: &str) -> String;
55-
5651
fn cpp_arg_post_call(&self, _name: &str) -> String {
5752
"".to_string()
5853
}
@@ -109,7 +104,7 @@ pub enum Indirection {
109104
}
110105

111106
impl fmt::Debug for RenderLane<'_, '_> {
112-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
107+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
113108
match self {
114109
RenderLane::Primitive(_) => f.write_str("Primitive"),
115110
RenderLane::InString(_) => f.write_str("InString"),

binding-generator/src/writer/rust_native/type_ref/render_lane/function.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ impl RenderLaneTrait for FunctionRenderLane<'_, '_> {
4848
.collect::<Vec<_>>();
4949
let fw_args = tramp_args
5050
.iter()
51-
.filter(|(is_user_data, _)| !is_user_data)
52-
.map(|(_, decl)| decl)
51+
.filter_map(|(is_user_data, decl)| (!is_user_data).then_some(decl))
5352
.join(", ");
5453
let ret = self.func.return_type();
5554
format!(

build/generator/collector.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ impl<'r> Collector<'r> {
190190
writeln!(hub_rs, "\nmod ffi_exports {{")?;
191191
writeln!(hub_rs, "\tuse crate::mod_prelude_sys::*;")?;
192192
write!(hub_rs, "\t")?;
193+
// MSRV: use #[unsafe(no_mangle)] when MSRV is 1.82
193194
writeln!(
194195
hub_rs,
195196
r#"#[no_mangle] unsafe extern "C" fn ocvrs_create_string{}(s: *const c_char) -> *mut String {{ crate::templ::ocvrs_create_string(s) }}"#,

ci/install-ubuntu.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,10 @@ if [[ "$OPENCV_VERSION" == "5.0.0-alpha" ]]; then
312312
BUILD_FLAGS="$BUILD_FLAGS -D WITH_QT=OFF"
313313
fi
314314

315-
pushd "$build_dir" > /dev/null
315+
cd "$build_dir"
316316
cmake $BUILD_FLAGS \
317317
-D CMAKE_INSTALL_PREFIX=/usr \
318318
-D OPENCV_EXTRA_MODULES_PATH="$opencv_contrib_src/modules" \
319319
"$opencv_src"
320320
make -j"$(nproc)"
321321
sudo make -j"$(nproc)" install
322-
popd > /dev/null

0 commit comments

Comments
 (0)