rust - Differences between `fn` and `||` in type for an array of functions -


I was doing some simple experiments in war, which included an array of tasks, and finally this working code Came out with:

  fn fun1 (arg: & string) - & gt; String {prefix = string :: se_strik ("a:"); Prefix.add (arg)} fn fun2 (Arg: & string) - & gt; String {prefix = string :: from_string ("b:"); Prefix.add (arg)} fn doall (arg: and string, funcs_vec: & amp; [fn (and string) -> string]) {for funcs_vec.iter (f) {println! ("{}", (* F) (RGR)); }} Fixed Fax: & amp; 'Stable [fn (and string) - & gt; String] = & amp; [Fun1, fun2]; Fn Main () {doall (and String :: from_str ("foo"), fx); }  

who prints:

  a: foo b: foo  

Then, reading, I have a syntax Seen | & Amp; String | - & gt; The string should also work, but trying it like this:

  fn doall (arg: & string, funcs_vec: & amp; [& string | - & gt; string]) {for funcs_vec.iter () {println! ("{}", (* F) (RGR)); }} Fixed funcs: & amp; 'Stable [| & String | - & gt; String] = & amp; [Fun1, fun2];  

There is a complaint with the compiler:

  funcarray.rs 17:25: 17:45 error: missing lifetime specifier funcarray.rs17 static fax: & amp; ; ; 'Stable [| & Amp; String | - & gt; String] = & amp; [Fun1, fun2]; ^ ~~~~~~~~~~~~~~~~~  

If I try to change this line:

  Stable Fashion: & amp; 'Stable [& amp; String |: 'static - & gt; String] = & amp; [Fun1, fun2];  

This gives me this error:

  funcarray.rs 17:57: 17:70 Error: Mismatch type: Expected `& amp; 'Stable [' stable | & Amp; Archive :: String :: String | - & gt; Collection :: string :: string: 'static]' but found that '& amp; Stable [FN (and archive :: string :: string) - & gt; Collection :: String :: String] `(Expected FN, but Extern FN found) funcarray.rs17 Fixed Fax: & amp; 'Static [& amp; String ;: 'Static - & gt; String] = & amp; [Fun1, fun2]; ^ ~~~~~~~~~~~~  

And here I am so lost What can I do to do this work (if this is possible)?

More generally, to specify the type of function in this array, what are the differences between these two syntax? It seems like to include births, but I can not understand it.

A function is quite different in pointers and closure rust.

List

  | T ... | - & gt; UFN (T ...) - & gt; Close as  temporary environment  and  bare function type  as the  

.

A closure is not a function of its environment.

A closing in the call stack can not be up , because the lifetime of the captured environment can not be specified / validated, no work takes nothing, therefore < Em> come back .

We do not have yet (discussed) non-capturing closures, i.e. there is a small syntax for writing. Anonymous actions

As you see, there is a significant semantics and syntax difference between the two and they are not interchangeable.

Interesting blog articles and more about reading about tasks and closing the road.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -