LINUX.ORG.RU

История изменений

Исправление fsb4000, (текущая версия) :

Что скажете, есть у него минусы по сравнению с вашим решением?

  1. Не собирается rustc, который в Debian 10(https://packages.debian.org/stable/rust/rustc):
rustc -C opt-level=3 2.rs
error[E0277]: expected a `std::ops::Fn<()>` closure, found `std::boxed::Box<[closure@2.rs:12:24: 12:43]>`
  --> 2.rs:16:17
   |
16 |         bx_cl = Box::new(cl1.clone());
   |                 ^^^^^^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `std::boxed::Box<[closure@2.rs:12:24: 12:43]>`
   |
   = help: the trait `std::ops::Fn<()>` is not implemented for `std::boxed::Box<[closure@2.rs:12:24: 12:43]>`
   = note: wrap the `std::boxed::Box<[closure@2.rs:12:24: 12:43]>` in a closure with no arguments: `|| { /* code */ }
   = note: required for the cast to the object type `dyn std::ops::Fn()`

error[E0277]: expected a `std::ops::Fn<()>` closure, found `std::boxed::Box<[closure@2.rs:13:24: 13:44]>`
  --> 2.rs:18:17
   |
18 |         bx_cl = Box::new(cl2.clone());
   |                 ^^^^^^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `std::boxed::Box<[closure@2.rs:13:24: 13:44]>`
   |
   = help: the trait `std::ops::Fn<()>` is not implemented for `std::boxed::Box<[closure@2.rs:13:24: 13:44]>`
   = note: wrap the `std::boxed::Box<[closure@2.rs:13:24: 13:44]>` in a closure with no arguments: `|| { /* code */ }
   = note: required for the cast to the object type `dyn std::ops::Fn()`

error[E0277]: expected a `std::ops::Fn<()>` closure, found `std::boxed::Box<[closure@2.rs:20:24: 20:37 cl1:_]>`
  --> 2.rs:24:18
   |
24 |         bx_cl2 = Box::new(cl3);
   |                  ^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `std::boxed::Box<[closure@2.rs:20:24: 20:37 cl1:_]>`
   |
   = help: the trait `std::ops::Fn<()>` is not implemented for `std::boxed::Box<[closure@2.rs:20:24: 20:37 cl1:_]>`
   = note: wrap the `std::boxed::Box<[closure@2.rs:20:24: 20:37 cl1:_]>` in a closure with no arguments: `|| { /* code */ }
   = note: required for the cast to the object type `dyn std::ops::Fn()`

error[E0277]: expected a `std::ops::Fn<()>` closure, found `std::boxed::Box<[closure@2.rs:21:24: 21:37 cl2:_]>`
  --> 2.rs:26:18
   |
26 |         bx_cl2 = Box::new(cl4);
   |                  ^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `std::boxed::Box<[closure@2.rs:21:24: 21:37 cl2:_]>`
   |
   = help: the trait `std::ops::Fn<()>` is not implemented for `std::boxed::Box<[closure@2.rs:21:24: 21:37 cl2:_]>`
   = note: wrap the `std::boxed::Box<[closure@2.rs:21:24: 21:37 cl2:_]>` in a closure with no arguments: `|| { /* code */ }
   = note: required for the cast to the object type `dyn std::ops::Fn()`

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0277`.
fsb4000@orangepilite2:~/rust$ rustc -V
rustc 1.34.2

  1. Вообще я хотел посмотреть в Valgrind число аллокаций, мне кажется у вашего варианта их будет чуть больше, даже не смотря на оптимизирующий компилятор, но rustc из Debian не захотел собирать…

А так вроде больше минусов нет…

Исходная версия fsb4000, :

Что скажете, есть у него минусы по сравнению с вашим решением?

  1. Не собирается rustc, который в Debian 10:
rustc -C opt-level=3 2.rs
error[E0277]: expected a `std::ops::Fn<()>` closure, found `std::boxed::Box<[closure@2.rs:12:24: 12:43]>`
  --> 2.rs:16:17
   |
16 |         bx_cl = Box::new(cl1.clone());
   |                 ^^^^^^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `std::boxed::Box<[closure@2.rs:12:24: 12:43]>`
   |
   = help: the trait `std::ops::Fn<()>` is not implemented for `std::boxed::Box<[closure@2.rs:12:24: 12:43]>`
   = note: wrap the `std::boxed::Box<[closure@2.rs:12:24: 12:43]>` in a closure with no arguments: `|| { /* code */ }
   = note: required for the cast to the object type `dyn std::ops::Fn()`

error[E0277]: expected a `std::ops::Fn<()>` closure, found `std::boxed::Box<[closure@2.rs:13:24: 13:44]>`
  --> 2.rs:18:17
   |
18 |         bx_cl = Box::new(cl2.clone());
   |                 ^^^^^^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `std::boxed::Box<[closure@2.rs:13:24: 13:44]>`
   |
   = help: the trait `std::ops::Fn<()>` is not implemented for `std::boxed::Box<[closure@2.rs:13:24: 13:44]>`
   = note: wrap the `std::boxed::Box<[closure@2.rs:13:24: 13:44]>` in a closure with no arguments: `|| { /* code */ }
   = note: required for the cast to the object type `dyn std::ops::Fn()`

error[E0277]: expected a `std::ops::Fn<()>` closure, found `std::boxed::Box<[closure@2.rs:20:24: 20:37 cl1:_]>`
  --> 2.rs:24:18
   |
24 |         bx_cl2 = Box::new(cl3);
   |                  ^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `std::boxed::Box<[closure@2.rs:20:24: 20:37 cl1:_]>`
   |
   = help: the trait `std::ops::Fn<()>` is not implemented for `std::boxed::Box<[closure@2.rs:20:24: 20:37 cl1:_]>`
   = note: wrap the `std::boxed::Box<[closure@2.rs:20:24: 20:37 cl1:_]>` in a closure with no arguments: `|| { /* code */ }
   = note: required for the cast to the object type `dyn std::ops::Fn()`

error[E0277]: expected a `std::ops::Fn<()>` closure, found `std::boxed::Box<[closure@2.rs:21:24: 21:37 cl2:_]>`
  --> 2.rs:26:18
   |
26 |         bx_cl2 = Box::new(cl4);
   |                  ^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `std::boxed::Box<[closure@2.rs:21:24: 21:37 cl2:_]>`
   |
   = help: the trait `std::ops::Fn<()>` is not implemented for `std::boxed::Box<[closure@2.rs:21:24: 21:37 cl2:_]>`
   = note: wrap the `std::boxed::Box<[closure@2.rs:21:24: 21:37 cl2:_]>` in a closure with no arguments: `|| { /* code */ }
   = note: required for the cast to the object type `dyn std::ops::Fn()`

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0277`.
fsb4000@orangepilite2:~/rust$ rustc -V
rustc 1.34.2

  1. Вообще я хотел посмотреть в Valgrind число аллокаций, мне кажется у вашего варианта их будет чуть больше, даже не смотря на оптимизирующий компилятор, но rustc из Debian не захотел собирать…

А так вроде больше минусов нет…