rust-unofficial/patterns

Incorrect text in Command pattern description

Offen

#346 geöffnet am 18.02.2023

 (0 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Shell (292 Forks)batch import
A-patternC-amendmentgood first issue

Repository-Metriken

Stars
 (6.622 Sterne)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

Since function pointers implement all three traits Fn, FnMut, and FnOnce we could as well pass and store closures instead of function pointers.

This is not exactly correct function pointers can be created only from non-capturing closures. Which can be easily verified if you change example little bit:

error[[E0308]](https://doc.rust-lang.org/stable/error_codes/E0308.html): mismatched types
  --> src/main.rs:41:26
   |
41 |     schema.add_migration(|| format!("create {}",table), || "drop table".to_string());
   |            ------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected fn pointer, found closure
   |            |
   |            arguments to this function are incorrect
   |
   = note: expected fn pointer `fn() -> String`
                 found closure `[closure@src/main.rs:41:26: 41:28]`
note: closures can only be coerced to `fn` types if they do not capture any variables

Contributor Guide