Rust 不匹配的类型,使用查找主机时应()找到结果

Rust 不匹配的类型,使用查找主机时应()找到结果,rust,Rust,我正在使用。当我构建时,会发生一个错误。我使用的是Rust 1.2 use std::net; fn main() { for host in try!(net::lookup_host("rust-lang.org")) { println!("found address : {}", try!(host)); } } 错误 :5:8:6:42错误:不匹配的类型: 期望`()`, 找到'core::result::result'` (预期为(), 找到枚举'c

我正在使用。当我构建时,会发生一个错误。我使用的是Rust 1.2

use std::net;
fn main() {
    for host in try!(net::lookup_host("rust-lang.org")) {
        println!("found address : {}", try!(host));
    }
}
错误

:5:8:6:42错误:不匹配的类型:
期望`()`,
找到'core::result::result'`
(预期为(),
找到枚举'core::result::result`)[E0308]
:5返回$CLATE::结果::结果::错误(
:6$crate::convert::From::From(err))})
:1:1:6:48注意:在试用的扩展中!
考试时间:4:14:4:53注:扩展站点
注:在循环扩展的扩展中
考试rs:4:2:6:3注:扩展站点
:5:8:6:42帮助:运行'rustc--explain E0308'查看详细说明
:5:8:6:42错误:不匹配的类型:
期望`()`,
找到'core::result::result'`
(预期为(),
找到枚举'core::result::result`)[E0308]
:5返回$CLATE::结果::结果::错误(
:6$crate::convert::From::From(err))})
:1:1:6:48注意:在试用的扩展中!
考试时间:5:34:5:44注:扩展站点
注意:在格式参数的扩展中!
:2:25:2:56注:扩展站点
:1:1:2:62注:在扩展打印中!
:3:1:3:54注:扩展站点
:1:1:3:58注:在println的扩展中!
考试rs:5:3:5:46注:扩展站点
注:在循环扩展的扩展中
考试rs:4:2:6:3注:扩展站点
:5:8:6:42帮助:运行'rustc--explain E0308'查看详细说明
错误:由于之前的两个错误而中止
只能从返回的函数中使用宏,因为如果表达式是
Err
,宏会尝试从函数中返回

#![feature(lookup_host)]

use std::io::Error;
use std::net;

fn main0() -> Result<(), Error> {
    for host in try!(net::lookup_host("rust-lang.org")) {
        println!("found address : {}", try!(host));
    }
    Ok(())
}

fn main() {
    // unwrap() will panic if main0() returns an error.
    main0().unwrap();
}
#![功能(查找主机)]
使用std::io::Error;
使用std::net;
fn main0()->结果{
用于try中的主机(net::lookup_host(“rust-lang.org”)){
println!(“找到地址:{}”,try!(主机));
}
好(())
}
fn main(){
//如果main0()返回错误,unwrap()将死机。
main0().unwrap();
}

Thx,但这是#![功能(查找\u主机)]是否可以在夜间版本中使用?
lookup\u主机
不稳定,因此目前只能在夜间版本中使用。这是
#![feature(lookup_host)]

use std::io::Error;
use std::net;

fn main0() -> Result<(), Error> {
    for host in try!(net::lookup_host("rust-lang.org")) {
        println!("found address : {}", try!(host));
    }
    Ok(())
}

fn main() {
    // unwrap() will panic if main0() returns an error.
    main0().unwrap();
}