优化代码

This commit is contained in:
李运家 2024-11-02 14:21:36 +08:00
parent 7b84948624
commit e5d9d07084
6 changed files with 10 additions and 10 deletions

View File

@ -195,10 +195,10 @@ impl Account {
($1, $2, $3, $4, $5) returning *
"#,
self.username,
self.google_id.clone().unwrap(),
self.email.clone().unwrap(),
self.display_name.clone().unwrap(),
self.avatar_url.clone().unwrap()
self.google_id.as_ref().unwrap(),
self.email.as_ref().unwrap(),
self.display_name.as_ref().unwrap(),
self.avatar_url.as_ref().unwrap()
)
.fetch_one(&mut **transaction)
.await

View File

@ -13,6 +13,6 @@ where
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
let context: &Context = parts.extensions.get().unwrap();
Ok(context.clone())
Ok(context.to_owned())
}
}

View File

@ -17,7 +17,7 @@ where
type Rejection = ResErr;
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
let context_parts = parts.clone();
let context_parts = parts.to_owned();
let context: &Context = context_parts.extensions.get().unwrap();
let lang_tag = context.get_lang_tag();

View File

@ -19,7 +19,7 @@ const WHITE_LIST: &[(&str, &str)] = &[
/// 认证中间件包括网络请求白名单、token验证、登录缓存
pub async fn authenticate_ctx(mut req: Request, next: Next) -> Response {
// 获取请求的url和method然后判断是否在白名单中如果在白名单中则直接返回next(req),否则继续执行下面的代码
let method = req.method().clone().to_string();
let method = req.method().as_str();
let mut uri = req.uri().path_and_query().unwrap().to_string();
uri = uri.replace(&config!().server.prefix_url, "");
tracing::debug!("请求路径: {}", uri);
@ -28,7 +28,7 @@ pub async fn authenticate_ctx(mut req: Request, next: Next) -> Response {
}).is_some() {
// 解析语言
let language = request_util::get_lang_tag(req.headers());
req.extensions_mut().insert(Context { lang_tag: Arc::new(language.clone()), account: None, token: None });
req.extensions_mut().insert(Context { lang_tag: Arc::new(language), account: None, token: None });
return next.run(req).await;
}

View File

@ -118,7 +118,7 @@ impl WechatSocial {
*wechat_access_token = new_wechat_access_token;
}
tracing::info!("wechat access token: {:?}", wechat_access_token);
Ok(wechat_access_token.clone())
Ok(wechat_access_token.to_owned())
}
/// 微信登录登录

View File

@ -103,7 +103,7 @@ impl Parse for Args {
impl Args {
pub fn get_arg(&self, index: usize) -> syn::Result<Option<syn::Expr>> {
match self.vars.get(index) {
Some(var) => Ok(Some(var.clone())),
Some(var) => Ok(Some(var.to_owned())),
None => {
// 第一个参数使路由url必须存在其他的参数根据实际需求进一步解析
if index != 0 {