1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-23 15:51:06 +01:00
This commit is contained in:
Rob Ede 2023-01-07 01:04:16 +00:00
parent 6848312467
commit 779860b664
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
13 changed files with 27 additions and 29 deletions

View File

@ -32,7 +32,8 @@ impl TestApp {
.listen(listener)
.unwrap()
.run();
let _ = actix_web::rt::spawn(server);
actix_web::rt::spawn(server);
let client = reqwest::Client::builder()
.cookie_store(true)

View File

@ -21,7 +21,7 @@ async fn test_limiter_count() -> Result<(), Error> {
for i in 0..20 {
let status = limiter.count(id.to_string()).await?;
println!("status: {:?}", status);
println!("status: {status:?}");
assert_eq!(20 - status.remaining(), i + 1);
}

View File

@ -39,15 +39,15 @@ pub enum ProtoBufPayloadError {
ContentType,
/// Serialize error
#[display(fmt = "ProtoBuf serialize error: {}", _0)]
#[display(fmt = "ProtoBuf serialize error: {_0}")]
Serialize(ProtoBufEncodeError),
/// Deserialize error
#[display(fmt = "ProtoBuf deserialize error: {}", _0)]
#[display(fmt = "ProtoBuf deserialize error: {_0}")]
Deserialize(ProtoBufDecodeError),
/// Payload error
#[display(fmt = "Error that occur during reading payload: {}", _0)]
#[display(fmt = "Error that occur during reading payload: {_0}")]
Payload(PayloadError),
}

View File

@ -13,7 +13,7 @@ pub use self::redis::{Command, RedisActor};
/// General purpose `actix-redis` error.
#[derive(Debug, Display, Error, From)]
pub enum Error {
#[display(fmt = "Redis error: {}", _0)]
#[display(fmt = "Redis error: {_0}")]
Redis(redis_async::error::Error),
/// Receiving message during reconnecting.

View File

@ -31,7 +31,7 @@ async fn test_redis() {
let res = addr.send(Command(resp_array!["GET", "test"])).await;
match res {
Ok(Ok(resp)) => {
println!("RESP: {:?}", resp);
println!("RESP: {resp:?}");
assert_eq!(resp, RespValue::BulkString((&b"value"[..]).into()));
}
_ => panic!("Should not happen {:?}", res),

View File

@ -3,11 +3,11 @@ use actix_web::{cookie::Key, middleware, web, App, Error, HttpRequest, HttpServe
/// simple handler
async fn index(req: HttpRequest, session: Session) -> Result<impl Responder, Error> {
println!("{:?}", req);
println!("{req:?}");
// session
if let Some(count) = session.get::<i32>("counter")? {
println!("SESSION value: {}", count);
println!("SESSION value: {count}");
session.insert("counter", count + 1)?;
} else {
session.insert("counter", 1)?;

View File

@ -179,7 +179,7 @@ pub mod test_helpers {
CookieContentSecurity::Signed,
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::expiration_is_refreshed_on_changes(store_builder.clone(), *policy)
.await;
@ -243,7 +243,7 @@ pub mod test_helpers {
}))
.service(web::resource("/test/").to(|ses: Session| async move {
let val: usize = ses.get("counter").unwrap().unwrap();
format!("counter: {}", val)
format!("counter: {val}")
})),
)
.await;
@ -710,9 +710,9 @@ pub mod test_helpers {
async fn logout(session: Session) -> Result<HttpResponse> {
let id: Option<String> = session.get("user_id")?;
let body = if let Some(x) = id {
let body = if let Some(id) = id {
session.purge();
format!("Logged out: {}", x)
format!("Logged out: {id}")
} else {
"Could not log out anonymous user".to_owned()
};

View File

@ -291,7 +291,7 @@ impl FromRequest for Session {
/// Error returned by [`Session::get`].
#[derive(Debug, Display, From)]
#[display(fmt = "{}", _0)]
#[display(fmt = "{_0}")]
pub struct SessionGetError(anyhow::Error);
impl StdError for SessionGetError {
@ -308,7 +308,7 @@ impl ResponseError for SessionGetError {
/// Error returned by [`Session::insert`].
#[derive(Debug, Display, From)]
#[display(fmt = "{}", _0)]
#[display(fmt = "{_0}")]
pub struct SessionInsertError(anyhow::Error);
impl StdError for SessionInsertError {

View File

@ -89,7 +89,7 @@ impl From<Error> for io::Error {
fn from(err: Error) -> Self {
match err {
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)
}
@ -105,32 +105,29 @@ impl From<Error> for io::Error {
line,
column,
} => {
let msg = format!(
"Expected {}, got {} (@ {}:{}:{})",
expected, got, file, line, column
);
let msg = format!("Expected {expected}, got {got} (@ {file}:{line}:{column})");
io::Error::new(io::ErrorKind::InvalidInput, msg)
}
Error::IoError(io_error) => io_error.into(),
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)
}
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)
}
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)
}
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)
}
}

View File

@ -274,7 +274,7 @@ where
todo!("[ApplySettings] TLS support has not been implemented yet.");
} else {
for Address { host, port } in &settings.actix.hosts {
self = self.bind(format!("{}:{}", host, port))
self = self.bind(format!("{host}:{port}"))
.unwrap(/*TODO*/);
}
}

View File

@ -6,7 +6,7 @@ async fn ok_validator(
req: ServiceRequest,
credentials: BearerAuth,
) -> Result<ServiceRequest, (Error, ServiceRequest)> {
eprintln!("{:?}", credentials);
eprintln!("{credentials:?}");
Ok(req)
}

View File

@ -32,7 +32,7 @@ impl fmt::Display for ParseError {
match self {
ParseError::Invalid => f.write_str("Invalid header value"),
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::Base64DecodeError(err) => fmt::Display::fmt(err, f),
ParseError::Utf8Error(err) => fmt::Display::fmt(err, f),

View File

@ -12,14 +12,14 @@ mod tests {
#[test]
fn to_bytes() {
let b = Bearer::build()
let bearer = Bearer::build()
.error(Error::InvalidToken)
.error_description("Subject 8740827c-2e0a-447b-9716-d73042e4039d not found")
.finish();
assert_eq!(
"Bearer error=\"invalid_token\" error_description=\"Subject 8740827c-2e0a-447b-9716-d73042e4039d not found\"",
format!("{}", b)
format!("{bearer}")
);
}
}