Switch to Rust 2018

This commit is contained in:
Frank Denis 2019-04-03 01:58:51 +02:00
parent e854072dbb
commit f339052e8c
3 changed files with 9 additions and 14 deletions

View File

@ -7,6 +7,7 @@ repository = "https://github.com/jedisct1/iptoasn-webservice"
keywords = ["ip", "asn", "bgp"] keywords = ["ip", "asn", "bgp"]
license = "MIT" license = "MIT"
authors = ["Frank Denis <github@pureftpd.org>"] authors = ["Frank Denis <github@pureftpd.org>"]
edition = "2018"
[dependencies] [dependencies]
clap = "2" clap = "2"

View File

@ -1,26 +1,20 @@
extern crate clap;
extern crate flate2;
#[macro_use] #[macro_use]
extern crate horrorshow; extern crate horrorshow;
extern crate hyper;
extern crate hyper_native_tls;
extern crate iron;
#[macro_use] #[macro_use]
extern crate log; extern crate log;
#[macro_use] #[macro_use]
extern crate router; extern crate router;
extern crate serde_json;
extern crate unicase;
mod asns; mod asns;
mod webservice; mod webservice;
use asns::*; use crate::asns::*;
use crate::webservice::*;
use clap::{App, Arg}; use clap::{App, Arg};
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
use webservice::*;
fn get_asns(db_url: &str) -> Result<ASNs, &'static str> { fn get_asns(db_url: &str) -> Result<ASNs, &'static str> {
info!("Retrieving ASNs"); info!("Retrieving ASNs");

View File

@ -1,4 +1,4 @@
use asns::*; use crate::asns::*;
use horrorshow::prelude::*; use horrorshow::prelude::*;
use iron::headers::{Accept, CacheControl, CacheDirective, Vary}; use iron::headers::{Accept, CacheControl, CacheDirective, Vary};
use iron::mime::*; use iron::mime::*;
@ -30,7 +30,7 @@ impl ASNsMiddleware {
} }
impl BeforeMiddleware for ASNsMiddleware { impl BeforeMiddleware for ASNsMiddleware {
fn before(&self, req: &mut Request) -> IronResult<()> { fn before(&self, req: &mut Request<'_, '_>) -> IronResult<()> {
req.extensions req.extensions
.insert::<ASNsMiddleware>(self.asns_arc.read().unwrap().clone()); .insert::<ASNsMiddleware>(self.asns_arc.read().unwrap().clone());
Ok(()) Ok(())
@ -45,7 +45,7 @@ enum OutputType {
pub struct WebService; pub struct WebService;
impl WebService { impl WebService {
fn index(_: &mut Request) -> IronResult<Response> { fn index(_: &mut Request<'_, '_>) -> IronResult<Response> {
Ok(Response::with(( Ok(Response::with((
status::Ok, status::Ok,
Mime( Mime(
@ -61,7 +61,7 @@ impl WebService {
))) )))
} }
fn accept_type(req: &Request) -> OutputType { fn accept_type(req: &Request<'_, '_>) -> OutputType {
let mut output_type = OutputType::Json; let mut output_type = OutputType::Json;
if let Some(header_accept) = req.headers.get::<Accept>() { if let Some(header_accept) = req.headers.get::<Accept>() {
for header in header_accept.iter() { for header in header_accept.iter() {
@ -183,7 +183,7 @@ impl WebService {
} }
} }
fn ip_lookup(req: &mut Request) -> IronResult<Response> { fn ip_lookup(req: &mut Request<'_, '_>) -> IronResult<Response> {
let mime_text = Mime( let mime_text = Mime(
TopLevel::Text, TopLevel::Text,
SubLevel::Plain, SubLevel::Plain,