These are chat archives for rust-lang/rust

17th
Nov 2018
tandrysyawaludin
@tandrysyawaludin
Nov 17 2018 04:05
how to debug Rust?
Tim Robinson
@1tgr
Nov 17 2018 07:27
gdb or lldb on the command line, or the JetBrains Rust plug-in in the CLion IDE
You have to pay for CLion but it’s available on 30 day trial
Otherwise: avoid the need to debug your code by writing plenty of small tests for different parts of it
Michal 'vorner' Vaner
@vorner
Nov 17 2018 09:12
I guess debugging without specialized tooling is somthing people just learn over time. But I wonder if it's something that could be learned from a tutorial or a class ‒ it's usually faster to debug by just looking at the input, output, logs and reading the relevant part of code, so it would make sense.
red75prime
@red75prime
Nov 17 2018 09:31
Also, Rust (failure::Error for that matter) allows to write programs which produce informative error messages: what, where, relevant context.
Roman Proskuryakov
@kpp
Nov 17 2018 09:33
How do I link WASM library into -sys crate? Is it the same as .so?
Windel Bouwman
@windelbouwman_twitter
Nov 17 2018 11:25
Hi! Currently I am working on RustPython. I have one issue I am unable to solve, maybe you have ideas / hints how to solve it. The problem I have is that I want to sort a vector, but the function sort_by (https://doc.rust-lang.org/std/primitive.slice.html#method.sort_by) should return a Cmp result. Now, I cannot use this since the comparison function actually might fail with a Result::Err result. How can I use a function which returns a Result as a compare function?
uncotion
@uncotion
Nov 17 2018 11:29

Hi,
I’m testing a piece of code in actin-web (actix web uses tokio event loop).
I got a problem with this, I don’t know how can I use ClientRequest in a function that executed by a system.

    actix::run(
        || client::get("http://www.rust-lang.org")   // <- Create request builder
            .header("User-Agent", "Actix-web")
            .finish().unwrap()
            .send()                               // <- Send http request
            .map_err(|_| ())
            .and_then(|response| {                // <- server http response
                println!("Response: {:?}", response);
                Ok(())
            })
    );

panicked at 'System is already running’ .

LeapM
@LeapM
Nov 17 2018 16:51
hello, can someone please help me with the syntax <type>::method()?
Associated item for a type that cannot be directly named (e.g., <&T>::..., <[T]>::..., etc.)
i think it is the above case, but have not idea of what it means
Sylwester Rąpała
@xoac
Nov 17 2018 17:06
@LeapM can u past error with code?
I don't mean all your code just rust error with surrounding information
LeapM
@LeapM
Nov 17 2018 17:07
image.png
it comes from the rust book
i am reading other people code and saw this syntax, and don't understand. there is no error, just trying to understand the syntax <type>::method_call
thanks Sylwek
<balances::Module<T>>::decrease_free_balance(&sender, payment)?;
his code is like this
Sylwester Rąpała
@xoac
Nov 17 2018 17:12
I understood it on json() function. image u have a pseudo function like json(bytes: &Bytes) -> T that transform bytes (that should be valid json) to T. Now how rust can know what the type u wanna to try deserialize bytes?
you can call it: let my_deserialized_type = json::<MyType>(&bytes) and now rust will try deserialize bytes into MyType if bytes are valid.
@LeapM I am not awesome in teaching so fell free to ask or saying u still don't understand
LeapM
@LeapM
Nov 17 2018 17:17
i think the case you explained is turbofish, which is used for generic methods call. I can be wrong
kraigher
@kraigher
Nov 17 2018 17:18
Is there some trait to say that a type generic must be an owned value?
I get errors like: error[E0310]: the parameter type T may not live long enough
I guess it is because T could be a reference
But I do not want to use it with references I only need it to work for owned data
kraigher
@kraigher
Nov 17 2018 17:27
For example if I want to send something through a channel
I want to say that the value is Send + Owned
kraigher
@kraigher
Nov 17 2018 17:42
I have searched for something like and Owned marker but cannot find it
kraigher
@kraigher
Nov 17 2018 17:58
Does + 'static also mean owned?
Sylwester Rąpała
@xoac
Nov 17 2018 18:01
if going about Owned trait I never here about it. I just saw in serde DeserializeOwned Mayby it will be useful for you.
I mean maybe u have the same problem and u can see to source code to check how it was resolved
kraigher
@kraigher
Nov 17 2018 18:10
It seems T : 'static works like Owned
I though 'static only mean stuff that lived as long as the program
But maybe an owned value in some scope qualifies
Denis Lisov
@tanriol
Nov 17 2018 20:16
IIUC, in generics 'static means not "must live to the end of the program", but "is not forced to die earlier than the end of the program". For example, a reference is forced to die before the referenced object dies, while a String has no such external limitations...
kraigher
@kraigher
Nov 17 2018 20:20
Yes an Owned value is to forced to die unless the owner wants to, it makes sense
I think maybe the error message from the compiler could be a bit better
It said I should have added 'static but I though "no I will use it for non-static owned values"
So it took me a while to try it
Maybe if Owned or 'owned was an alias for 'static it would have made it more intuitive for me at least
Denis Lisov
@tanriol
Nov 17 2018 20:35
This is not exactly correct. For example, technically you own a reference to some data. You may own an struct that contains a reference... and it still must die before whatever it refers to dies, thus it would not be 'static
kraigher
@kraigher
Nov 17 2018 20:36
True
I must just have got the wrong mental model of what 'static was used for
But now I know better. Maybe there will be more people after me making the same mistake
Sylwester Rąpała
@xoac
Nov 17 2018 22:02
io::Cursor<Bytes> impl Read and Buf both traits has a bytes() method why rust is using from Read::bytes() instead warn me that there are 2 functions?
Sylwester Rąpała
@xoac
Nov 17 2018 22:07

Strange:

          for b in self.reader.bytes() {
>>            if *b == 0xFF {
                  skip += 1;
              } else {
                  break;
              }
          }

give me error:

error[E0614]: type `std::result::Result<u8, std::io::Error>` cannot be dereferenced
  --> src/soft.rs:93:16
   |
93 |             if *b == 0xFF {
   |                ^^

With just this change it works fine..

          for b in Buf::bytes(&self.reader) {
              if *b == 0xFF {
                  skip += 1;
              } else {
                  break;
              }
          }
Félix Fischer
@felix91gr
Nov 17 2018 22:33
Hello
:)
I've been reading the rustc guide a bit, because I'm making a compiler. However, now I'm at the step of Code Generation and I have no idea where to look for Rust tooling on that regard, since the chapter is still unfinished. Do y'all know what does rustc use? Maybe I can use the same and check out its docs :)
Denis Lisov
@tanriol
Nov 17 2018 22:36
Rustc uses LLVM for code generation. There are talks about alternate backends like Cranelift, but none are working yet AFAIK.
Félix Fischer
@felix91gr
Nov 17 2018 22:37
Ohh, I didn't know there were thoughts about using alternate backends :D that sounds really cool
I know about LLVM, I guess I didn't phrased my question well enough ^^. What I wanna know is if there is a crate or a repository with bindings to LLVM, that rustc might be using
Denis Lisov
@tanriol
Nov 17 2018 22:39
I'd suggest you may try looking into Cranelift, as it is being developed as a Rust-based code generator.
Regarding LLVM bindings, they live in the rust git tree, not on crates.io
Denis Lisov
@tanriol
Nov 17 2018 22:44
Félix Fischer
@felix91gr
Nov 17 2018 22:52
I see I have a lot to read. Thank you! :D