mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-23 15:51:06 +01:00
clippy
This commit is contained in:
parent
6848312467
commit
779860b664
@ -32,7 +32,8 @@ impl TestApp {
|
|||||||
.listen(listener)
|
.listen(listener)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.run();
|
.run();
|
||||||
let _ = actix_web::rt::spawn(server);
|
|
||||||
|
actix_web::rt::spawn(server);
|
||||||
|
|
||||||
let client = reqwest::Client::builder()
|
let client = reqwest::Client::builder()
|
||||||
.cookie_store(true)
|
.cookie_store(true)
|
||||||
|
@ -21,7 +21,7 @@ async fn test_limiter_count() -> Result<(), Error> {
|
|||||||
|
|
||||||
for i in 0..20 {
|
for i in 0..20 {
|
||||||
let status = limiter.count(id.to_string()).await?;
|
let status = limiter.count(id.to_string()).await?;
|
||||||
println!("status: {:?}", status);
|
println!("status: {status:?}");
|
||||||
assert_eq!(20 - status.remaining(), i + 1);
|
assert_eq!(20 - status.remaining(), i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,15 +39,15 @@ pub enum ProtoBufPayloadError {
|
|||||||
ContentType,
|
ContentType,
|
||||||
|
|
||||||
/// Serialize error
|
/// Serialize error
|
||||||
#[display(fmt = "ProtoBuf serialize error: {}", _0)]
|
#[display(fmt = "ProtoBuf serialize error: {_0}")]
|
||||||
Serialize(ProtoBufEncodeError),
|
Serialize(ProtoBufEncodeError),
|
||||||
|
|
||||||
/// Deserialize error
|
/// Deserialize error
|
||||||
#[display(fmt = "ProtoBuf deserialize error: {}", _0)]
|
#[display(fmt = "ProtoBuf deserialize error: {_0}")]
|
||||||
Deserialize(ProtoBufDecodeError),
|
Deserialize(ProtoBufDecodeError),
|
||||||
|
|
||||||
/// Payload error
|
/// Payload error
|
||||||
#[display(fmt = "Error that occur during reading payload: {}", _0)]
|
#[display(fmt = "Error that occur during reading payload: {_0}")]
|
||||||
Payload(PayloadError),
|
Payload(PayloadError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ pub use self::redis::{Command, RedisActor};
|
|||||||
/// General purpose `actix-redis` error.
|
/// General purpose `actix-redis` error.
|
||||||
#[derive(Debug, Display, Error, From)]
|
#[derive(Debug, Display, Error, From)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[display(fmt = "Redis error: {}", _0)]
|
#[display(fmt = "Redis error: {_0}")]
|
||||||
Redis(redis_async::error::Error),
|
Redis(redis_async::error::Error),
|
||||||
|
|
||||||
/// Receiving message during reconnecting.
|
/// Receiving message during reconnecting.
|
||||||
|
@ -31,7 +31,7 @@ async fn test_redis() {
|
|||||||
let res = addr.send(Command(resp_array!["GET", "test"])).await;
|
let res = addr.send(Command(resp_array!["GET", "test"])).await;
|
||||||
match res {
|
match res {
|
||||||
Ok(Ok(resp)) => {
|
Ok(Ok(resp)) => {
|
||||||
println!("RESP: {:?}", resp);
|
println!("RESP: {resp:?}");
|
||||||
assert_eq!(resp, RespValue::BulkString((&b"value"[..]).into()));
|
assert_eq!(resp, RespValue::BulkString((&b"value"[..]).into()));
|
||||||
}
|
}
|
||||||
_ => panic!("Should not happen {:?}", res),
|
_ => panic!("Should not happen {:?}", res),
|
||||||
|
@ -3,11 +3,11 @@ use actix_web::{cookie::Key, middleware, web, App, Error, HttpRequest, HttpServe
|
|||||||
|
|
||||||
/// simple handler
|
/// simple handler
|
||||||
async fn index(req: HttpRequest, session: Session) -> Result<impl Responder, Error> {
|
async fn index(req: HttpRequest, session: Session) -> Result<impl Responder, Error> {
|
||||||
println!("{:?}", req);
|
println!("{req:?}");
|
||||||
|
|
||||||
// session
|
// session
|
||||||
if let Some(count) = session.get::<i32>("counter")? {
|
if let Some(count) = session.get::<i32>("counter")? {
|
||||||
println!("SESSION value: {}", count);
|
println!("SESSION value: {count}");
|
||||||
session.insert("counter", count + 1)?;
|
session.insert("counter", count + 1)?;
|
||||||
} else {
|
} else {
|
||||||
session.insert("counter", 1)?;
|
session.insert("counter", 1)?;
|
||||||
|
@ -179,7 +179,7 @@ pub mod test_helpers {
|
|||||||
CookieContentSecurity::Signed,
|
CookieContentSecurity::Signed,
|
||||||
CookieContentSecurity::Private,
|
CookieContentSecurity::Private,
|
||||||
] {
|
] {
|
||||||
println!("Using {:?} as cookie content security policy.", policy);
|
println!("Using {policy:?} as cookie content security policy.");
|
||||||
acceptance_tests::basic_workflow(store_builder.clone(), *policy).await;
|
acceptance_tests::basic_workflow(store_builder.clone(), *policy).await;
|
||||||
acceptance_tests::expiration_is_refreshed_on_changes(store_builder.clone(), *policy)
|
acceptance_tests::expiration_is_refreshed_on_changes(store_builder.clone(), *policy)
|
||||||
.await;
|
.await;
|
||||||
@ -243,7 +243,7 @@ pub mod test_helpers {
|
|||||||
}))
|
}))
|
||||||
.service(web::resource("/test/").to(|ses: Session| async move {
|
.service(web::resource("/test/").to(|ses: Session| async move {
|
||||||
let val: usize = ses.get("counter").unwrap().unwrap();
|
let val: usize = ses.get("counter").unwrap().unwrap();
|
||||||
format!("counter: {}", val)
|
format!("counter: {val}")
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
@ -710,9 +710,9 @@ pub mod test_helpers {
|
|||||||
async fn logout(session: Session) -> Result<HttpResponse> {
|
async fn logout(session: Session) -> Result<HttpResponse> {
|
||||||
let id: Option<String> = session.get("user_id")?;
|
let id: Option<String> = session.get("user_id")?;
|
||||||
|
|
||||||
let body = if let Some(x) = id {
|
let body = if let Some(id) = id {
|
||||||
session.purge();
|
session.purge();
|
||||||
format!("Logged out: {}", x)
|
format!("Logged out: {id}")
|
||||||
} else {
|
} else {
|
||||||
"Could not log out anonymous user".to_owned()
|
"Could not log out anonymous user".to_owned()
|
||||||
};
|
};
|
||||||
|
@ -291,7 +291,7 @@ impl FromRequest for Session {
|
|||||||
|
|
||||||
/// Error returned by [`Session::get`].
|
/// Error returned by [`Session::get`].
|
||||||
#[derive(Debug, Display, From)]
|
#[derive(Debug, Display, From)]
|
||||||
#[display(fmt = "{}", _0)]
|
#[display(fmt = "{_0}")]
|
||||||
pub struct SessionGetError(anyhow::Error);
|
pub struct SessionGetError(anyhow::Error);
|
||||||
|
|
||||||
impl StdError for SessionGetError {
|
impl StdError for SessionGetError {
|
||||||
@ -308,7 +308,7 @@ impl ResponseError for SessionGetError {
|
|||||||
|
|
||||||
/// Error returned by [`Session::insert`].
|
/// Error returned by [`Session::insert`].
|
||||||
#[derive(Debug, Display, From)]
|
#[derive(Debug, Display, From)]
|
||||||
#[display(fmt = "{}", _0)]
|
#[display(fmt = "{_0}")]
|
||||||
pub struct SessionInsertError(anyhow::Error);
|
pub struct SessionInsertError(anyhow::Error);
|
||||||
|
|
||||||
impl StdError for SessionInsertError {
|
impl StdError for SessionInsertError {
|
||||||
|
@ -89,7 +89,7 @@ impl From<Error> for io::Error {
|
|||||||
fn from(err: Error) -> Self {
|
fn from(err: Error) -> Self {
|
||||||
match err {
|
match err {
|
||||||
Error::EnvVarError(var_error) => {
|
Error::EnvVarError(var_error) => {
|
||||||
let msg = format!("Env var error: {}", var_error);
|
let msg = format!("Env var error: {var_error}");
|
||||||
io::Error::new(io::ErrorKind::InvalidInput, msg)
|
io::Error::new(io::ErrorKind::InvalidInput, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,32 +105,29 @@ impl From<Error> for io::Error {
|
|||||||
line,
|
line,
|
||||||
column,
|
column,
|
||||||
} => {
|
} => {
|
||||||
let msg = format!(
|
let msg = format!("Expected {expected}, got {got} (@ {file}:{line}:{column})");
|
||||||
"Expected {}, got {} (@ {}:{}:{})",
|
|
||||||
expected, got, file, line, column
|
|
||||||
);
|
|
||||||
io::Error::new(io::ErrorKind::InvalidInput, msg)
|
io::Error::new(io::ErrorKind::InvalidInput, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
Error::IoError(io_error) => io_error.into(),
|
Error::IoError(io_error) => io_error.into(),
|
||||||
|
|
||||||
Error::ParseBoolError(parse_bool_error) => {
|
Error::ParseBoolError(parse_bool_error) => {
|
||||||
let msg = format!("Failed to parse boolean: {}", parse_bool_error);
|
let msg = format!("Failed to parse boolean: {parse_bool_error}");
|
||||||
io::Error::new(io::ErrorKind::InvalidInput, msg)
|
io::Error::new(io::ErrorKind::InvalidInput, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
Error::ParseIntError(parse_int_error) => {
|
Error::ParseIntError(parse_int_error) => {
|
||||||
let msg = format!("Failed to parse integer: {}", parse_int_error);
|
let msg = format!("Failed to parse integer: {parse_int_error}");
|
||||||
io::Error::new(io::ErrorKind::InvalidInput, msg)
|
io::Error::new(io::ErrorKind::InvalidInput, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
Error::ParseAddressError(string) => {
|
Error::ParseAddressError(string) => {
|
||||||
let msg = format!("Failed to parse address: {}", string);
|
let msg = format!("Failed to parse address: {string}");
|
||||||
io::Error::new(io::ErrorKind::InvalidInput, msg)
|
io::Error::new(io::ErrorKind::InvalidInput, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
Error::TomlError(toml_error) => {
|
Error::TomlError(toml_error) => {
|
||||||
let msg = format!("TOML error: {}", toml_error);
|
let msg = format!("TOML error: {toml_error}");
|
||||||
io::Error::new(io::ErrorKind::InvalidInput, msg)
|
io::Error::new(io::ErrorKind::InvalidInput, msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -274,7 +274,7 @@ where
|
|||||||
todo!("[ApplySettings] TLS support has not been implemented yet.");
|
todo!("[ApplySettings] TLS support has not been implemented yet.");
|
||||||
} else {
|
} else {
|
||||||
for Address { host, port } in &settings.actix.hosts {
|
for Address { host, port } in &settings.actix.hosts {
|
||||||
self = self.bind(format!("{}:{}", host, port))
|
self = self.bind(format!("{host}:{port}"))
|
||||||
.unwrap(/*TODO*/);
|
.unwrap(/*TODO*/);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ async fn ok_validator(
|
|||||||
req: ServiceRequest,
|
req: ServiceRequest,
|
||||||
credentials: BearerAuth,
|
credentials: BearerAuth,
|
||||||
) -> Result<ServiceRequest, (Error, ServiceRequest)> {
|
) -> Result<ServiceRequest, (Error, ServiceRequest)> {
|
||||||
eprintln!("{:?}", credentials);
|
eprintln!("{credentials:?}");
|
||||||
Ok(req)
|
Ok(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ impl fmt::Display for ParseError {
|
|||||||
match self {
|
match self {
|
||||||
ParseError::Invalid => f.write_str("Invalid header value"),
|
ParseError::Invalid => f.write_str("Invalid header value"),
|
||||||
ParseError::MissingScheme => f.write_str("Missing authorization scheme"),
|
ParseError::MissingScheme => f.write_str("Missing authorization scheme"),
|
||||||
ParseError::MissingField(field) => write!(f, "Missing header field ({})", field),
|
ParseError::MissingField(field) => write!(f, "Missing header field ({field})"),
|
||||||
ParseError::ToStrError(err) => fmt::Display::fmt(err, f),
|
ParseError::ToStrError(err) => fmt::Display::fmt(err, f),
|
||||||
ParseError::Base64DecodeError(err) => fmt::Display::fmt(err, f),
|
ParseError::Base64DecodeError(err) => fmt::Display::fmt(err, f),
|
||||||
ParseError::Utf8Error(err) => fmt::Display::fmt(err, f),
|
ParseError::Utf8Error(err) => fmt::Display::fmt(err, f),
|
||||||
|
@ -12,14 +12,14 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_bytes() {
|
fn to_bytes() {
|
||||||
let b = Bearer::build()
|
let bearer = Bearer::build()
|
||||||
.error(Error::InvalidToken)
|
.error(Error::InvalidToken)
|
||||||
.error_description("Subject 8740827c-2e0a-447b-9716-d73042e4039d not found")
|
.error_description("Subject 8740827c-2e0a-447b-9716-d73042e4039d not found")
|
||||||
.finish();
|
.finish();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"Bearer error=\"invalid_token\" error_description=\"Subject 8740827c-2e0a-447b-9716-d73042e4039d not found\"",
|
"Bearer error=\"invalid_token\" error_description=\"Subject 8740827c-2e0a-447b-9716-d73042e4039d not found\"",
|
||||||
format!("{}", b)
|
format!("{bearer}")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user