These are chat archives for rust-lang/rust

8th
Apr 2019
thojest
@thojest
Apr 08 18:37
hay i have a question: what does the '_ mean in pub fn pull_tweets(&self) -> impl Future<Item = Vec<Tweet>, Error = TweetScraperError> + '_
i know it's something about lifetime but what exactly?
Ingvar Stepanyan
@RReverser
Apr 08 18:38
just "some unnamed lifetime"
thojest
@thojest
Apr 08 18:38
what do I need it?
Ingvar Stepanyan
@RReverser
Apr 08 18:38
in this case it's just to bind it to the unnamed lifetime of &self
thojest
@thojest
Apr 08 18:39
ahh so return value lives as long as &self?
Ingvar Stepanyan
@RReverser
Apr 08 18:39

so

pub fn pull_tweets(&self) -> impl Future<Item = Vec<Tweet>, Error = TweetScraperError> + '_

is the same as

pub fn pull_tweets<'a>(&'a self) -> impl Future<Item = Vec<Tweet>, Error = TweetScraperError> + 'a
thojest
@thojest
Apr 08 18:39
ahh many thx @RReverser
Ingvar Stepanyan
@RReverser
Apr 08 18:39
np
thojest
@thojest
Apr 08 19:07
is the lifetime of the returned future implicitly static?
when I dont use a lifetime parameter
and the compiler does not complain
matrixbot
@matrixbot
Apr 08 19:21
bspeice When you return an owned object, it's effectively static. When you return references, that's when things get interesting.
David Holroyd
@dholroyd
Apr 08 21:50
within a loop body, I have a collection containing some mutable references to items in another collection; all is well if the collection containing the references is allocated in the loop body, but I can't see how to 'hoist' the allocation of this collection out of the loop -- the compiler sees the possibility of mut references persisting between iterations, and of course simply clearing the collection is not enough to convince the compiler otherwise
I think perf is telling me that it would be worth saving the allocation
Denis Lisov
@tanriol
Apr 08 21:52
What collection and how many references?
David Holroyd
@dholroyd
Apr 08 21:53
it's an iovec kind of arrangement
I'm currently just using Vec, but open to other options
Denis Lisov
@tanriol
Apr 08 21:56
And what's the normal number of buffers in one call?
David Holroyd
@dholroyd
Apr 08 21:57
testing with 8 at the moment; normal usage might be a 10-100s
FWIW, I am actually trying to use recvmmsg(2) from rust, if that helps understand the goal
Denis Lisov
@tanriol
Apr 08 22:01
First, I'd suggest that perf testing should be done close to normal usage as the allocation cost is going to be smaller in that case relative to the other costs :-)
Second, I'd look at SmallVec or something like it to avoid the heap allocation.
David Holroyd
@dholroyd
Apr 08 22:03
Oh, that's a great idea, will take look!
David Holroyd
@dholroyd
Apr 08 22:43
changing from Vec to SmallVec angers the borrow check :'(
curious!
David Holroyd
@dholroyd
Apr 08 22:56
well, fixed in that example with an explicit drop(), but I can't actually see how the change to SmallVec altered the extent of the lifetime