These are chat archives for rust-lang/rust

10th
Sep 2017
Restioson
@Restioson
Sep 10 2017 10:06
Hey guys
anyone know why I can't get xz2 working on windows?
error: failed to run custom build command for `lzma-sys v0.1.8`
Looks like microsoft build tools don't like me
Alexander.Positivinn
@ailjushkin_twitter
Sep 10 2017 11:32
@Restioson
Restioson
@Restioson
Sep 10 2017 11:32
Hi!
Alexander.Positivinn
@ailjushkin_twitter
Sep 10 2017 11:35
Hi, what version of c++ build tools do you have? Maybe there's something that is not in your path environment
Restioson
@Restioson
Sep 10 2017 11:36
I've given up on it now though :/
Realised needed to do something else, anyways (xz2 wouldn't have done the job)
thanks for looking though :)
Moggers
@Moggers
Sep 10 2017 16:06
is this an appropriate place for baby questions?
David Harvey-Macaulay
@alteous
Sep 10 2017 16:07
@Moggers Yes, fire away!
Moggers
@Moggers
Sep 10 2017 16:09
I'm getting an error about std::marker::Sized not being implemented by std::error::Error and that its required by std::result::Result, this makes sense considering that std::error::Error is a trait and not a concrete type
but how do I use ? operator in my method if the different things I call return different implementations of std::error::Error?
because I'm trying to return an std::result::Result<Thing,std::error::Error>
David Harvey-Macaulay
@alteous
Sep 10 2017 16:12
@Moggers You're right about the sized issue. Since Error is a trait its size is not known at compile time. Instead, try putting it on the heap, i.e. return a Result<Thing, Box<Error>> instead.
Moggers
@Moggers
Sep 10 2017 16:12
but in that case, how can I use a ? operator on vendor functions?
waaitt
I dont have to do anything?
I guess I'll go find out what a Box<> actually is O.o
thanks a bunch @alteous !
David Harvey-Macaulay
@alteous
Sep 10 2017 16:13
No problem. :smile:
Box is a container for a single item on the heap, which is implemented as simply a pointer. A pointer has a known size at compile time, regardless of what it points to.
Moggers
@Moggers
Sep 10 2017 16:14
yep, I got that
Im just wondering why I don't have to explicitly reference it
David Harvey-Macaulay
@alteous
Sep 10 2017 16:15
Because Box<T> implements Deref<Item = T>.
Moggers
@Moggers
Sep 10 2017 16:15
why I can just return an std::error::Error and thats valid as an Box<std::error::Error>
like I thought I would have to call Box::new(err)
on it or something like that
This message was deleted
David Harvey-Macaulay
@alteous
Sep 10 2017 16:16
Yes, you would have to in any other situation. There's a bit of implicit magic in the case of Box<Error>.
Moggers
@Moggers
Sep 10 2017 16:16
O.o
David Harvey-Macaulay
@alteous
Sep 10 2017 16:17
That is, there is an automatic conversion to Box<Error> when you use the ? operator and the return value is Result<T, Box<Error>>.
Of course, only for error types that implement Error.
Moggers
@Moggers
Sep 10 2017 16:19
hmm
does that kind of thing happen elsewhere?
implicit boxing where its required to match the type?
David Harvey-Macaulay
@alteous
Sep 10 2017 16:21
I think that's the only case to allow for prototyping without having to worry about the error type.
Usually, an application will return its own error type defined as enum AppError { LibError0(...), LibError1(...) } etc.
Restioson
@Restioson
Sep 10 2017 16:22
@Moggers I think the call to Deref<T> is automatically inserted at compile time, so you don't need to explicitly deref :smile:
Moggers
@Moggers
Sep 10 2017 16:23
when trying to access whatever the Box contains?
David Harvey-Macaulay
@alteous
Sep 10 2017 16:23
Restioson
@Restioson
Sep 10 2017 16:23
Yes, or a method on it
Moggers
@Moggers
Sep 10 2017 16:23
cool
Restioson
@Restioson
Sep 10 2017 16:24
which is useful. You could write your own pointer to a ram chip (for embedded, etc) and use it like a normal pointer!
Moggers
@Moggers
Sep 10 2017 16:24
oh right, its not just a Box::Deref, its ANY implementation of deref?
Restioson
@Restioson
Sep 10 2017 16:24
^-^