Auto merge of #26212 - Manishearth:rollup, r=Manishearth
- Successful merges: #26181, #26184, #26189, #26191, #26195, #26202 - Failed merges:
This commit is contained in:
commit
deff2f50a9
6 changed files with 34 additions and 38 deletions
|
|
@ -30,15 +30,13 @@ You may also be interested in browsing [trending Rust repositories][github-rust]
|
|||
|
||||
## Is anyone using Rust in production?
|
||||
|
||||
Currently, Rust is still pre-1.0, and so we don't recommend that you use Rust
|
||||
in production unless you know exactly what you're getting into.
|
||||
|
||||
That said, there are two production deployments of Rust that we're aware of:
|
||||
Yes. For example (incomplete):
|
||||
|
||||
* [OpenDNS](http://labs.opendns.com/2013/10/04/zeromq-helping-us-block-malicious-domains/)
|
||||
* [Skylight](http://skylight.io)
|
||||
|
||||
Let the fact that this is an easily countable number be a warning.
|
||||
* [wit.ai](https://github.com/wit-ai/witd)
|
||||
* [Codius](https://codius.org/blog/codius-rust/)
|
||||
* [MaidSafe](http://maidsafe.net/)
|
||||
|
||||
## Does it run on Windows?
|
||||
|
||||
|
|
|
|||
|
|
@ -324,37 +324,34 @@ first, it may seem strange, but we’ll figure it out. Here’s how you’d prob
|
|||
try to return a closure from a function:
|
||||
|
||||
```rust,ignore
|
||||
fn factory() -> (Fn(i32) -> Vec<i32>) {
|
||||
let vec = vec![1, 2, 3];
|
||||
fn factory() -> (Fn(i32) -> i32) {
|
||||
let num = 5;
|
||||
|
||||
|n| vec.push(n)
|
||||
|x| x + num
|
||||
}
|
||||
|
||||
let f = factory();
|
||||
|
||||
let answer = f(4);
|
||||
assert_eq!(vec![1, 2, 3, 4], answer);
|
||||
let answer = f(1);
|
||||
assert_eq!(6, answer);
|
||||
```
|
||||
|
||||
This gives us these long, related errors:
|
||||
|
||||
```text
|
||||
error: the trait `core::marker::Sized` is not implemented for the type
|
||||
`core::ops::Fn(i32) -> collections::vec::Vec<i32>` [E0277]
|
||||
f = factory();
|
||||
^
|
||||
note: `core::ops::Fn(i32) -> collections::vec::Vec<i32>` does not have a
|
||||
constant size known at compile-time
|
||||
f = factory();
|
||||
^
|
||||
error: the trait `core::marker::Sized` is not implemented for the type
|
||||
`core::ops::Fn(i32) -> collections::vec::Vec<i32>` [E0277]
|
||||
factory() -> (Fn(i32) -> Vec<i32>) {
|
||||
^~~~~~~~~~~~~~~~~~~~~
|
||||
note: `core::ops::Fn(i32) -> collections::vec::Vec<i32>` does not have a constant size known at compile-time
|
||||
factory() -> (Fn(i32) -> Vec<i32>) {
|
||||
^~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
`core::ops::Fn(i32) -> i32` [E0277]
|
||||
fn factory() -> (Fn(i32) -> i32) {
|
||||
^~~~~~~~~~~~~~~~
|
||||
note: `core::ops::Fn(i32) -> i32` does not have a constant size known at compile-time
|
||||
fn factory() -> (Fn(i32) -> i32) {
|
||||
^~~~~~~~~~~~~~~~
|
||||
error: the trait `core::marker::Sized` is not implemented for the type `core::ops::Fn(i32) -> i32` [E0277]
|
||||
let f = factory();
|
||||
^
|
||||
note: `core::ops::Fn(i32) -> i32` does not have a constant size known at compile-time
|
||||
let f = factory();
|
||||
^
|
||||
```
|
||||
|
||||
In order to return something from a function, Rust needs to know what
|
||||
|
|
@ -364,16 +361,16 @@ way to give something a size is to take a reference to it, as references
|
|||
have a known size. So we’d write this:
|
||||
|
||||
```rust,ignore
|
||||
fn factory() -> &(Fn(i32) -> Vec<i32>) {
|
||||
let vec = vec![1, 2, 3];
|
||||
fn factory() -> &(Fn(i32) -> i32) {
|
||||
let num = 5;
|
||||
|
||||
|n| vec.push(n)
|
||||
|x| x + num
|
||||
}
|
||||
|
||||
let f = factory();
|
||||
|
||||
let answer = f(4);
|
||||
assert_eq!(vec![1, 2, 3, 4], answer);
|
||||
let answer = f(1);
|
||||
assert_eq!(6, answer);
|
||||
```
|
||||
|
||||
But we get another error:
|
||||
|
|
@ -448,7 +445,8 @@ assert_eq!(6, answer);
|
|||
We use a trait object, by `Box`ing up the `Fn`. There’s just one last problem:
|
||||
|
||||
```text
|
||||
error: `num` does not live long enough
|
||||
error: closure may outlive the current function, but it borrows `num`,
|
||||
which is owned by the current function [E0373]
|
||||
Box::new(|x| x + num)
|
||||
^~~~~~~~~~~
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue