Rust "expected identifier, found keyword" 导入

Rust "expected identifier, found keyword" on importing

我有两个文件,loop.rs 包含一个函数请求,用于实例化客户端并获取网页正文。我想将请求导出到 main.我知道要导出我需要 mod file_to_import 然后 use file_to_import::function_to_use 根据 this post

src/
   main.rs
   loop.rs


// loop.rs ->
//crates
extern crate futures;
extern crate hyper;
extern crate tokio_core;
use std::io::{self, Write};
use self::futures::{Future, Stream};
use self::hyper::Client;
use self::tokio_core::reactor::Core;


//request function to be exported to main.rs

pub fn request(url: &str)  {
   let mut core = Core::new().unwrap();
   let client = Client::new(&core.handle());
   let uri = url.parse().unwrap();
   let work = client.get(uri).and_then(|res| {
      println!("Response: {}", res.status());

      res.body().for_each(|chunk| {
         io::stdout()
         .write_all(&chunk)
         .map_err(From::from)
     })
});
core.run(work).unwrap();
}


// main.rs ->
mod loop;
use loop::request;

fn main(){
   request("http://www.google.com");
}

在 main.rs 中,我想使用请求,但是当我构建它时,出现以下错误

error: expected identifier, found keyword `loop`
 --> src/main.rs:1:5
  |
1 | mod loop;
  |     ^^^^ expected identifier, found keyword

error: expected identifier, found keyword `loop`
 --> src/server.rs:1:5
  |
1 | use loop::{request};
  |     ^^^^ expected identifier, found keyword

error: expected identifier, found keyword `loop`
 --> src/main.rs:4:5
  |
4 | use loop::*;
  |     ^^^^ expected identifier, found keyword

loop 在 Rust 中是一个 keyword,这意味着它由解析器特殊处理,不能用作标识符。