These are chat archives for rust-lang/rust

18th
Feb 2019
Andrea Stevanato
@thymbahutymba
Feb 18 08:04
Hi, there are some way to know the last nightly that include clippy and rls, I saw from this link https://mexus.github.io/rustup-components-history/ that are missing from a while.
Kevin Wang
@kvinwang
Feb 18 12:49
Hi there, why does trait objects require the concrete type to be Sized?
Zakarum
@omni-viral
Feb 18 12:57
You can't create dyn Trait from ?Sized type
This is because pointer to ?SIzed type is already fat - two usize
For instance &[T] stores pointer and size
dyn Trait stores pointer to data and pointer to table of methods
Hense you can't create &dyn Trait from &[T] because it would require more space than usual
Kevin Wang
@kvinwang
Feb 18 13:07
@omni-viral got it. thanks a lot.
tsoernes
@tsoernes
Feb 18 17:23
If I have a HashMap<u32, Box<'a + FnMut(T) -> ()>>, populated with two functions fnA and fnB, and I then remove fnA from the HashMap so that there are no references to it anywhere (it goes out of scope), will it then live on on the heap, because the other function (fnB) still exists and they have the same lifetime?
Fixer
@DivineSymmetry_gitlab
Feb 18 17:47
If I learn typescript can I skip learning about javascript? Or how does that work?
matrixbot
@matrixbot
Feb 18 17:48
bspeice Typescript just compiles down to Javascript; there are still plenty of Javascript quirks, and you'll need to know it for debugging.
James McCoy
@jamessan
Feb 18 17:54
@tsoernes Lifetimes are descriptive, not prescriptive. They don't impose a certain lifetime, just give a name to the existing lifetime so that it's easier to describe relationships among lifetimes, allowing others (API users, compiler, etc.) to properly reason about them.
tsoernes
@tsoernes
Feb 18 17:57
@jamessan I think I understand, in which case the answer to the question is that fnA does not continue to live on. But is not 'static prescriptive?
i.e if I changed 'a to 'static would not the function continue to live on (i.e. take memory on the heap) even if removed from the hashmap (then dropped)?
James McCoy
@jamessan
Feb 18 18:02
@tsoernes Not as I understand it. You're just stating that any value inserted into the hash needs to have a static lifetime, so the compiler will use that information when compiling your code to decide whether the hash is being used appropriately. The lifetime of items inserted into the hash won't change.
Andrea Stevanato
@thymbahutymba
Feb 18 18:30
There is a way that given an Iterator of 100 partition it into iterator that containts 100/10 iterator containing 10 elements of the first one?
I would the inverse of flatten
Denis Lisov
@tanriol
Feb 18 18:32
Sounds like Itertools::chunks?
Zakarum
@omni-viral
Feb 18 19:41
@tsoernes There is a common misunderstanding between Type<'a> and &'a Type( that can be read as SharedRef<'a, Type>).
&'a Type is a type with lifetime 'a. But to create instance of it you must borrow a value of type Type with lifetime 'a or greater.
On the other hand values of Type<'a> cannot live longer than 'a
This means Box<'a + T> can live no longer than 'a and memory is freed once box is dropped
Andrea Stevanato
@thymbahutymba
Feb 18 20:02
@tanriol thanks!