These are chat archives for rust-lang/rust

5th
Nov 2017
Chirag Khandelwal
@Electrux
Nov 05 2017 07:54
hello everyone… I am new to rust and to gitter for that matter… wanted to know that in functions do i have to type return if I am returning something before the last statment of function?
something like this...
fn first_word( s: & String ) -> usize
{
    let bytes = s.as_bytes();

    for ( i, & item ) in bytes.iter().enumerate() {
        if item == b' ' {
            i
        }
    }

    s.len()
}
Do i need to write return i instead?
Matthias Bartelmeß
@fourplusone
Nov 05 2017 08:01
yes
Chirag Khandelwal
@Electrux
Nov 05 2017 08:01
why is that? if i may ask
Michal 'vorner' Vaner
@vorner
Nov 05 2017 08:09
@Electrux Because how otherwise would the program know not to continue with s.len()? Return is basically „skip over the rest of the function“
Chirag Khandelwal
@Electrux
Nov 05 2017 08:12
oh… umm so… s.len() doesnt actually return the value from the function, it just returns the value but since it is last statement in the function, the function returns that value? @vorner
Michal 'vorner' Vaner
@vorner
Nov 05 2017 08:12
Yes.
Chirag Khandelwal
@Electrux
Nov 05 2017 08:14
ok thanks a ton @vorner and @fourplusone :)
Judson Lester
@nyarly
Nov 05 2017 18:51
What's the simplest approach to an SSL service in Rust?
I don't see an immediate in to using hyper...
Judson Lester
@nyarly
Nov 05 2017 20:06
tokio-tls has a "hyper-server" example that seems to be what I want...
Judson Lester
@nyarly
Nov 05 2017 22:16
Is there really not a decent way to shut down a tokio server?
Denis Lisov
@tanriol
Nov 05 2017 22:24
Please detail "decent"
Judson Lester
@nyarly
Nov 05 2017 23:07
How about "any way" - I want to return a last response and then shutdown the HTTP server - without exiting the program.
Slowly seeing how maybe there'd be a way to .and_then( spawn(<something>); the_response)
Denis Lisov
@tanriol
Nov 05 2017 23:12
For example, at some point you have a Stream of new connections. You can insert a .take_while(|_| !my_atomic_shutdown_flag.load()) or something like that :-)