These are chat archives for rust-lang/rust

1st
Jan 2019
serde gives me an invalid digit error on "" wrapped hex strings, but looking at the stack trace I can't figure out where the error is coming from. My deserialize function isn't even hit, it just panics seemingly out of nowhere
any suggestions for interpreting this?
Michal 'vorner' Vaner
@vorner
Jan 01 19:12
@jkilpatr The sad thing about .unwrap is that something somewhere first creates the error, returns out of the place and returns the error. Then you unwrap it somewhere else and get backtrace of the somewhere else, not from the place the error was created.
When the panic happens, you're inside the .unwrap, not inside the from_str.
Justin Kilpatrick
@jkilpatr
Jan 01 19:48
huh sounds like I should just break out gdb to find the unwrap then
Zakarum
@omni-viral
Jan 01 19:53
Usually unwrap is just down the line. So from unwrap position you can find error cause
Ayush Prashar
@ayushprashar
Jan 01 23:01
Hey Guys
Can someone explain why is this code giving me a type mismatch?
fn linear_search(data: &[usize],to_find: &usize) -> bool {
for data_element in data {
if data_element == to_find {
true
}
}
false
}
Denis Lisov
@tanriol
Jan 01 23:05
The body of the for loop is expected to have a type of ()
Also, the else branch is missing, which is equivalent to else {} and also has a type of ()
Ayush Prashar
@ayushprashar
Jan 01 23:07
ok
thanks denis
can I specify a return type to for?
Denis Lisov
@tanriol
Jan 01 23:11
AFAIK, you cannot. And, honestly, being able to ignore return in some places does not mean you need to every time :-)
Ayush Prashar
@ayushprashar
Jan 01 23:20
ok, I couldn't make much sense of the latter half of your message but thanks a lot for your help
Denis Lisov
@tanriol
Jan 01 23:26
Looks like you meant to write
fn linear_search(data: &[usize], to_find: &usize) -> bool {
    for data_element in data {
        if data_element == to_find {
            return true;
        }
    }
    false
}
Ayush Prashar
@ayushprashar
Jan 01 23:28
thanks a lot Denis :D