These are chat archives for rust-lang/rust

17th
Aug 2018
trsh
@trsh
Aug 17 2018 08:54
@tanriol im expiremnting with boxes! Should this work on the paper https://pastebin.com/sUC1Knvr ? Because It doesn't. Confused again.
Denis Lisov
@tanriol
Aug 17 2018 09:06
Note that you store a pointer to ClientDetail in ns2__AddressValidationRequest, but the box containing the ns2__ClientDetail is dropped at the end of get_ns2__AddressValidationRequest
trsh
@trsh
Aug 17 2018 09:10
ahh
Tochukwu Nkemdilim
@TNkemdilim
Aug 17 2018 09:10

Please how can I assert_eq!(...) an enum of this sort: Implementing the PartialEq trait would allow comparism for Error::AnotherError but not for Error::Io(std::io::Error) as the compiler outputs

binary operation `==` cannot be applied to type `std::io::Error`

I was planning on implementing the PartialEq trait manually, but I don't know if this is the best approach.

#[derive(PartialEq)]
pub enum Error {
    Io(std::io::Error),
    AnotherError
}
Denis Lisov
@tanriol
Aug 17 2018 09:12
@TNkemdilim You may want to take a look at the matches crate macros
Tochukwu Nkemdilim
@TNkemdilim
Aug 17 2018 09:12
Thanks...
trsh
@trsh
Aug 17 2018 09:14
@tanriol do you have any idea, how get around this?
Denis Lisov
@tanriol
Aug 17 2018 09:28
Box::into_raw is more appropriate for this use case.
trsh
@trsh
Aug 17 2018 09:31
Yes! I just opened you first example from yd and understood that
And ti's working
Denis Lisov
@tanriol
Aug 17 2018 09:32
Don't forget about Drop to avoid leaking memory :-)
trsh
@trsh
Aug 17 2018 09:32
Sure
@tanriol I wish I could buy you a Beer :D
tnx
Denis Lisov
@tanriol
Aug 17 2018 09:35
Given your kind of code I'd even suggest running your test suite (sure you do have one, correct?) under valgrind to find all memory leaks and stop them.
trsh
@trsh
Aug 17 2018 09:38
Will take this into account
trsh
@trsh
Aug 17 2018 11:41
ghh "Copy not allowed on types with destructors"
Denis Lisov
@tanriol
Aug 17 2018 11:42
And you shall not use Copy on anything that contains an owned pointer (even if this is a raw pointer).
trsh
@trsh
Aug 17 2018 11:51
@tanriol also the problem is, when I for ex Implement Drop for client detail, And it gets out of scope, it's drop right. So that would call my fn and destroy it. But still the ClientDetail pointer is used for AddressValidationRequest.
Sylwester Rąpała
@xoac
Aug 17 2018 12:00

How would u change this future to None before return (comment line)?

          if let Some(fut) = &mut self.fut {
              match fut.poll() {
                  Ok(Async::Ready(chunks)) => {
                      // self.fut = None;
                      return Ok(Async::Ready(Some(chunks)));
                  }
                  Ok(Async::NotReady) => (),
                  Err(err) => {
                      // we retry here since fogger can be temporary unavailable
                      error!("ObjObserver {:?}", err);
                      fut_is_err = true;
                  }
              }
          }

My idea is to create mut temp_chunks and set bool flag to know it's done or not?
But it looks awful

trsh
@trsh
Aug 17 2018 12:02
I see, that a drop, for boxed and Into_raw is no called, unless I do from_raw for the box
This gives me some control
Denis Lisov
@tanriol
Aug 17 2018 12:17
It can, but it's not required to. However, if I add just one unrelated line...
trsh
@trsh
Aug 17 2018 12:55
hhee
Fantasized
@Fantasized
Aug 17 2018 14:20
Is this a good place for beginner question?
Denis Lisov
@tanriol
Aug 17 2018 14:20
Sure, go ahead.
Fantasized
@Fantasized
Aug 17 2018 14:26

TY, I was just going through the rust book and i just want to confirm something about control-flow statements

loop { } - In loop expression(i believe it is an expression) i can return a useful value via break like let stuff = loop { break 5};

but with while i can't do that stuff right? or am not doing it correctly?
let obj = while cond {
if..something..happens
break returnThevalueWe'veProcessed
}

Denis Lisov
@tanriol
Aug 17 2018 14:31
You cannot, E0571
With RFC 2046 when it's implemented it will be possible to do a break out of a labelled block with value, but not while loops IIUC.
Fantasized
@Fantasized
Aug 17 2018 14:43

ok, but doesn't it reasonable?

if break with useful value isn't supported should I've to do

let mut some:i32;

while cond {
.................
if x {
break (some = value)
}
} rather than let some = while cond {}

Denis Lisov
@tanriol
Aug 17 2018 14:44
What are you trying to do? :-)
Fantasized
@Fantasized
Aug 17 2018 14:51
TBH, am not actually doing anything serious , I was just thinking through my reading about each topics and if I get stuck somewhere( like i did with while) I try do understand its reasons( like why X is X ? or for some reasons if X isn't X what is the possible work-around to make it as X?)
Denis Lisov
@tanriol
Aug 17 2018 14:53
Well, the reason is pretty obvious :-) what should the return value be if cond is false when trying to enter the loop for the first time?
Fantasized
@Fantasized
Aug 17 2018 15:25

In your case, if I annotate my variable with type let some:i32 = while cond {} and cond fails for the first time(I've assumed some can be value initialized for the type i32 and I realized it won't happen ),yet am also seeing a different problem (related to type inference ) not sure whether it is correct or not

while cond1 {
if cond2 {
break some
}
} what is the type that while should return typeof some or ? because cond2 result may not be predictable at compile time and we can't also write awhile like
while (cond) ->i32{ } if i want to break out with some useful values

Denis Lisov
@tanriol
Aug 17 2018 15:27
By the way, on gitter you can have multiline codeblocks by wrapping the code in triple backticks (on their own lines before and after)
It's the other side of the same problem... you would need all the ways out of the loop to have the same type. In theory it could be possible to wrap the value in an Option, but that would be weird.
This kind of code is quite often better written either as a combinator chain, or even split off in a separate function with a good name :-)
Rishav Sharan
@rishavs
Aug 17 2018 16:02

Hi. I am first time user trying out rust. I am unable to get it to work on my windows 10, x64 machine. Cargo run always times out;

PS C:\Users\Mockingbird\DevSpace\Actix\hello> cargo run
    Updating registry `https://github.com/rust-lang/crates.io-index`
warning: spurious network error (2 tries remaining): failed to send request: The operation timed out
; class=Os (2)
warning: spurious network error (1 tries remaining): failed to send request: The operation timed out
; class=Os (2)
error: failed to load source for a dependency on `actix-web`

Caused by:
  Unable to update registry `https://github.com/rust-lang/crates.io-index`

Caused by:
  failed to fetch `https://github.com/rust-lang/crates.io-index`

Caused by:
  failed to send request: The operation timed out
; class=Os (2)

I am not behind any proxy. I have added inbound/outbound rules in my windows firewall for cargo.exe. I have even uninstalled my antivirus. I still can't run cargo.