These are chat archives for rust-lang/rust

6th
May 2018
Restioson
@Restioson
May 06 2018 09:49
@mexus it should build it with test = true.
Sjoerd
@Sjoerrdd
May 06 2018 11:01
Hello o/
apiraino
@apiraino
May 06 2018 11:02
Hi @Sjoerrdd
Frederic
@just_fred_perry_twitter
May 06 2018 11:03
HI @Sjoerrdd
Restioson
@Restioson
May 06 2018 11:03
Hi @Sjoerrdd
Frederic
@just_fred_perry_twitter
May 06 2018 11:03
Can rust use QT?
Restioson
@Restioson
May 06 2018 11:03
yes
Frederic
@just_fred_perry_twitter
May 06 2018 11:05
the rust can be use in where?
only for website?
Restioson
@Restioson
May 06 2018 11:05
Rust can be used for virtually everything
Frederic
@just_fred_perry_twitter
May 06 2018 11:06
OK thank you @Restioson
i will study it
Liyakhath A. Syed
@smarlewy
May 06 2018 12:52
what's the point of unit testing in rust
not in rust .. but in genereal
Hans W. Uhlig
@huhlig
May 06 2018 12:52
same as it is in all languages
testing individual units of code
Liyakhath A. Syed
@smarlewy
May 06 2018 12:52
i never done it before
i mean.. what does it check..(is it like travisci?
apiraino
@apiraino
May 06 2018 12:55
@smarlewy I see that you have a lot of interesting questions and that's great. However I suggest choosing one topic at a time and take your time to understand the basics of that topic
Check the resources online and do some experimentation, that's the best way to get a feeling of what you're learning
Liyakhath A. Syed
@smarlewy
May 06 2018 12:56
haha okay..
sure
apiraino
@apiraino
May 06 2018 12:59
it's fantastic when there's a lot to learn, but computer science is not like reading a book "cover to cover" to be able to say "ok, now I know that topic". We're not in the Matrix, unfortunately :)
Liyakhath A. Syed
@smarlewy
May 06 2018 13:02
that's a bad habit i guess. to be wanting to know everything..
Dylan DPC
@Dylan-DPC
May 06 2018 13:21
true better to stick to a certain field and explore that in depth
Danilo Silva
@silvadanilo
May 06 2018 17:30
Hi all
can you help me with a signature problem?
I don't understan how to indicate the return type of a function that returns a futures::Lazy struct
this is my sample code, the fn asyncPrintln should return what the futures::lazy method returns (that is a Lazy structure)
extern crate futures;

use futures::future::lazy;
use futures::future::Lazy;
use futures::{Future, IntoFuture};

pub fn asyncPrintln<R, F>(msg: String) -> Lazy<R, F>
    where F: futures::Future,
          R: IntoFuture
{
    lazy(move || -> Result<(), ()> {
        println!("{}", msg);
        Ok(())
    })
}

fn main() {
    asyncPrintln("foo".to_string()).wait();
}
Danilo Silva
@silvadanilo
May 06 2018 17:36
I get this error:
error[E0308]: mismatched types
  --> src/main.rs:11:10
   |
11 |       lazy(move || -> Result<(), ()> {
   |  __________^
12 | |         println!("{}", msg);
13 | |         Ok(())
14 | |     })
   | |_____^ expected type parameter, found closure
   |
   = note: expected type `R`
              found type `[closure@src/main.rs:11:10: 14:6 msg:_]`

error[E0277]: the trait bound `R: std::ops::FnOnce<()>` is not satisfied
  --> src/main.rs:11:5
   |
11 |     lazy(move || -> Result<(), ()> {
   |     ^^^^ the trait `std::ops::FnOnce<()>` is not implemented for `R`
   |
   = help: consider adding a `where R: std::ops::FnOnce<()>` bound
   = note: required by `futures::lazy`
Denis
@mexus
May 06 2018 17:53
hey @silvadanilo, are you using futures 0.1 or 0.2 ?
and nightly or stable?
anyhow, you can't use generics to derive the return type
generics on a function only apply to its signature, disregarding the body
if you are on nightly with futures 0.1, consider the following:
extern crate futures;

use futures::Future;

pub fn async_println(msg: String) -> impl Future<Item = (), Error = ()> {
    futures::lazy(move || {
        println!("{}", msg);
        Ok(())
    })
}

fn main() {
    async_println("foo".to_string()).wait().unwrap();
}
Denis
@mexus
May 06 2018 17:58
if on stable, then
extern crate futures;

use futures::Future;

pub fn async_println(msg: String) -> Box<Future<Item = (), Error = ()>> {
    Box::new(futures::lazy(move || {
        println!("{}", msg);
        Ok(())
    }))
}

fn main() {
    async_println("foo".to_string()).wait().unwrap();
}
Danilo Silva
@silvadanilo
May 06 2018 18:04
stable (but I can switch on nightly if it is needed, I'm just training)
and futures 0.1
Denis
@mexus
May 06 2018 18:05
then i'd suggest switching to nightly then since it's more feature rich and use my example with impl Trait (... -> impl Future<...>)
Danilo Silva
@silvadanilo
May 06 2018 18:05
can I use an alias?
Denis
@mexus
May 06 2018 18:06
an alias?
Danilo Silva
@silvadanilo
May 06 2018 18:07
a type defined by me
I would like somethig like:
pub fn async_println(msg: String) -> Task<()> {
Denis
@mexus
May 06 2018 18:08
you definitely can, but it will be complicated
but you won't be able to do type Task = impl Future<... though
Danilo Silva
@silvadanilo
May 06 2018 18:09
ok, thanks @mexus!
I've been working for hours!
Denis
@mexus
May 06 2018 18:10
yw :)
Danilo Silva
@silvadanilo
May 06 2018 18:17
@mexus can I also ask you how to do a function that receives a Lazy, please?
Liyakhath A. Syed
@smarlewy
May 06 2018 18:19
Can I get a discord rust link?
Danilo Silva
@silvadanilo
May 06 2018 18:31
something like this:
pub fn async_get_line() -> impl Future<Item = String, Error = ()> {
    futures::lazy(|| {
        let mut input = String::new();
        io::stdin().read_line(&mut input);
        ok(input)
    })
}

pub fn with_message(msg: String, next: ????????) -> impl Future<Item = String, Error = ()> {
}

fn main() {
    let get_line = async_get_line();
    let question = with_message("Prova a indovinare: " . to_string(), get_line);
}
Denis
@mexus
May 06 2018 18:47
like this?
pub fn async_get_line() -> impl Future<Item = String, Error = ()> {
    futures::lazy(|| {
        let mut input = String::new();
        io::stdin().read_line(&mut input).unwrap();
        ok(input)
    })
}

pub fn with_message<T>(_msg: String, next: T) -> impl Future<Item = String, Error = ()>
where
    T: Future<Item = String, Error = ()>,
{
    // something something
    next
}

fn main() {
    let get_line = async_get_line();
    let _question = with_message("Prova a indovinare: ".to_string(), get_line)
        .wait()
        .unwrap();
}
Danilo Silva
@silvadanilo
May 06 2018 18:52
yes
very thanks :heart:
Denis
@mexus
May 06 2018 19:14
:+1:
prego :)
Danilo Silva
@silvadanilo
May 06 2018 19:24
:D