mirror of
https://github.com/actix/actix-extras.git
synced 2025-02-22 18:33:18 +01:00
better nightly detection
This commit is contained in:
parent
f33c489154
commit
59b8214685
@ -32,9 +32,6 @@ tls = ["native-tls", "tokio-tls"]
|
|||||||
# openssl
|
# openssl
|
||||||
alpn = ["openssl", "openssl/v102", "openssl/v110", "tokio-openssl"]
|
alpn = ["openssl", "openssl/v102", "openssl/v110", "tokio-openssl"]
|
||||||
|
|
||||||
# nightly
|
|
||||||
nightly = []
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
failure = "0.1"
|
failure = "0.1"
|
||||||
@ -91,6 +88,7 @@ skeptic = "0.13"
|
|||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
skeptic = "0.13"
|
skeptic = "0.13"
|
||||||
|
version_check = "0.1"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
|
13
build.rs
13
build.rs
@ -1,4 +1,6 @@
|
|||||||
extern crate skeptic;
|
extern crate skeptic;
|
||||||
|
extern crate version_check;
|
||||||
|
|
||||||
use std::{env, fs};
|
use std::{env, fs};
|
||||||
|
|
||||||
|
|
||||||
@ -11,8 +13,19 @@ fn main() {
|
|||||||
let f = env::var("OUT_DIR").unwrap() + "/skeptic-tests.rs";
|
let f = env::var("OUT_DIR").unwrap() + "/skeptic-tests.rs";
|
||||||
let _ = fs::File::create(f);
|
let _ = fs::File::create(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match version_check::is_nightly() {
|
||||||
|
Some(true) => println!("cargo:rustc-cfg=actix_nightly"),
|
||||||
|
Some(false) => (),
|
||||||
|
None => (),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
fn main() {
|
fn main() {
|
||||||
|
match version_check::is_nightly() {
|
||||||
|
Some(true) => println!("cargo:rustc-cfg=actix_nightly"),
|
||||||
|
Some(false) => (),
|
||||||
|
None => (),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
17
src/error.rs
17
src/error.rs
@ -4,7 +4,7 @@ use std::str::Utf8Error;
|
|||||||
use std::string::FromUtf8Error;
|
use std::string::FromUtf8Error;
|
||||||
use std::io::Error as IoError;
|
use std::io::Error as IoError;
|
||||||
|
|
||||||
#[cfg(feature="nightly")]
|
#[cfg(actix_nightly)]
|
||||||
use std::error::Error as StdError;
|
use std::error::Error as StdError;
|
||||||
|
|
||||||
use cookie;
|
use cookie;
|
||||||
@ -76,11 +76,11 @@ impl<T: ErrorResponse> From<T> for Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Default error is `InternalServerError`
|
/// Default error is `InternalServerError`
|
||||||
#[cfg(feature="nightly")]
|
#[cfg(actix_nightly)]
|
||||||
default impl<T: StdError + Sync + Send + 'static> ErrorResponse for T {
|
default impl<T: StdError + Sync + Send + 'static> ErrorResponse for T {
|
||||||
fn error_response(&self) -> HttpResponse {
|
fn error_response(&self) -> HttpResponse {
|
||||||
HttpResponse::new(StatusCode::INTERNAL_SERVER_ERROR, Body::Empty)
|
HttpResponse::new(StatusCode::INTERNAL_SERVER_ERROR, Body::Empty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `InternalServerError` for `JsonError`
|
/// `InternalServerError` for `JsonError`
|
||||||
@ -343,6 +343,13 @@ mod tests {
|
|||||||
use cookie::ParseError as CookieParseError;
|
use cookie::ParseError as CookieParseError;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(actix_nightly)]
|
||||||
|
fn test_nightly() {
|
||||||
|
let resp: HttpResponse = IoError::new(io::ErrorKind::Other, "test").error_response();
|
||||||
|
assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_into_response() {
|
fn test_into_response() {
|
||||||
let resp: HttpResponse = ParseError::Incomplete.error_response();
|
let resp: HttpResponse = ParseError::Incomplete.error_response();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Web framework for [Actix](https://github.com/actix/actix)
|
//! Web framework for [Actix](https://github.com/actix/actix)
|
||||||
|
|
||||||
#![cfg_attr(feature="nightly", feature(
|
#![cfg_attr(actix_nightly, feature(
|
||||||
specialization, // for impl ErrorResponse for std::error::Error
|
specialization, // for impl ErrorResponse for std::error::Error
|
||||||
))]
|
))]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user