futures-rs | Zero-cost asynchronous programming in Rust | Reactive Programming library
kandi X-RAY | futures-rs Summary
kandi X-RAY | futures-rs Summary
Zero-cost asynchronous programming in Rust. futures-rs is a library providing the foundations for asynchronous programming in Rust. It includes key trait definitions like Stream, as well as utilities like join!, select!, and various futures combinator methods which enable expressive asynchronous control flow.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of futures-rs
futures-rs Key Features
futures-rs Examples and Code Snippets
Community Discussions
Trending Discussions on futures-rs
QUESTION
I'm using the future library and I have a future which implements Future
. I'd like to map this future with a function FnOnce(T) -> D
where D: From
. Now when I want to wait()
for this future to finsih, I'll get a Result, D>
, however I'd like a Result
.
Here's some example code for better understanding:
...ANSWER
Answered 2020-Feb-02 at 16:23This is for futures v0.1 (old, experimental)
I found an answer to the question:
You can just first wait
on the future to finish, use ?
to return a potential error and then apply parse
on it:
QUESTION
I want to use the async
function to parse the inbound stream progressively, but actix-web requires impl Future
as the return value.
How can I convert the future returned by async
function to what actix-web requires?
I'm using Rust 1.39 nightly and actix-web 1.0.7.
http_srv.rs :
...ANSWER
Answered 2019-Oct-29 at 17:22std::future
-> future@0.1
conversion steps:
- The future needs to be
TryFuture
(Output = Result
) - The future needs to be
Unpin
(you can useboxed
combinator) - Finally, you can call the
compat
combinator
Your inbound
function:
QUESTION
There is an async
connect()
function as below.
ANSWER
Answered 2019-Aug-29 at 00:14let future01 = future03.unit_error().boxed_local().compat();
QUESTION
I'm writing a future combinator that needs to consume a value that it was provided with. With futures 0.1, Future::poll
took self: &mut Self
, which effectively meant that my combinator contained an Option
and I called Option::take
on it when the underlying future resolves.
The Future::poll
method in the standard library takes self: Pin<&mut Self>
instead, so I've been reading about the guarantees required in order to safely make use of Pin
.
From the pin
module documentation on the Drop
guarantee (emphasis mine):
Concretely, for pinned data you have to maintain the invariant that its memory will not get invalidated from the moment it gets pinned until when drop is called. Memory can be invalidated by deallocation, but also by replacing a
Some(v)
byNone
, or callingVec::set_len
to "kill" some elements off of a vector.
And Projections and Structural Pinning (emphasis mine):
You must not offer any other operations that could lead to data being moved out of the fields when your type is pinned. For example, if the wrapper contains an
Option
and there is a take-like operation with typefn(Pin<&mut Wrapper>) -> Option
, that operation can be used to move aT
out of a pinnedWrapper
-- which means pinning cannot be structural.
However, the existing Map
combinator calls Option::take
on a member value when the underlying future has resolved:
ANSWER
Answered 2019-Jun-22 at 17:41edit: This answer is incorrect. It remains here for posterity.
Let's begin by recalling why Pin
was introduced in the first place: we want to statically ensure that self-referential futures cannot be moved, thus invalidating their internal references.
With that in mind, let's take a look at the definition of Map
.
QUESTION
I am using a futures-rs powered version of the Rusoto AWS Kinesis library. I need to spawn a deep pipeline of AWS Kinesis requests to achieve high-throughput because Kinesis has a limit of 500 records per HTTP request. Combined with the 50ms latency of sending a request, I need to start generating many concurrent requests. I am looking to create somewhere on the order of 100 in-flight requests.
The Rusoto put_records
function signature looks like this:
ANSWER
Answered 2018-Jan-30 at 10:20As far as I can tell your problem with channel
is not that a single clone of the Sender
increase the capacity by one, it is that you clone the Sender
for every item you're trying to send.
The error you're seeing without clone
comes from your incorrect usage of the Sink::send
interface. With clone
you actually should see the warning:
QUESTION
Using the futures-rs
library, I've encountered a situation where a stream needs to be mapped through an indeterminate number of other streams before being returned to the user. Since the exact type of the output stream is unknown at the end of this operation, I've been using a BoxStream
trait object while storing the stream in a struct and when returning it.
Although this approach works fine, it has the unfortunate side effect of causing the inner Stream
object to be unsized. This is a problem because every one of the stream combinators require Self: Sized
in their signatures meaning that I can't even wait()
on the returned BoxStream
in order to convert it into a blocking iterator.
Here's an example of a situation that could lead to this issue:
...ANSWER
Answered 2017-Jan-22 at 02:05As pointed out by @FrancisGagné in a comment, futures-rs
declares impl Stream for Box
in the futures::Stream
module. In the test in which my code was, I had failed to import Stream
so that trait wasn't in scope.
The compiler didn't trigger an error for the lack of the wait()
function because it had the unsized issue first.
This was resolved by adding use futures::Stream;
to the start of the function.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install futures-rs
Rust is installed and managed by the rustup tool. Rust has a 6-week rapid release process and supports a great number of platforms, so there are many builds of Rust available at any time. Please refer rust-lang.org for more information.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page