Skip to content

Commit

Permalink
replace &** with .as_ref()
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Mar 19, 2024
1 parent ba20d91 commit 6119a9d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/api/ai_explain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub async fn explain(
)));
}
}
if let Some(client) = &**openai_client {
if let Some(client) = openai_client.as_ref() {
let explain_req = prepare_explain_req(explain_request, client).await?;
let stream = client.chat().create_stream(explain_req).await.unwrap();

Expand Down
4 changes: 2 additions & 2 deletions src/api/ai_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ pub async fn ai_help(
}
current
};
if let (Some(client), Some(pool)) = (&**openai_client, &**supabase_pool) {
if let (Some(client), Some(pool)) = (openai_client.as_ref(), supabase_pool.as_ref()) {
let ChatRequestMessages {
chat_id: chat_id_opt,
parent_id,
Expand Down Expand Up @@ -503,7 +503,7 @@ pub async fn ai_help_title_summary(
let settings = get_settings(&mut conn, &user)?;

if history_enabled(&settings) {
if let Some(client) = &**openai_client {
if let Some(client) = openai_client.as_ref() {
let hit = help_history_get_message(&mut conn, &user, &message_id.into_inner())?;
if let Some(hit) = hit {
let log_message = AIHelpLogMessage::from(hit);
Expand Down
8 changes: 4 additions & 4 deletions src/api/newsletter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub async fn subscribe_handler(
) -> Result<HttpResponse, ApiError> {
let mut conn = pool.get()?;
let user = get_user(&mut conn, user_id.id()?)?;
if let Some(basket) = &**basket {
if let Some(basket) = basket.as_ref() {
return subscribe(&mut conn, &user, basket).await;
}
Ok(HttpResponse::NotImplemented().finish())
Expand All @@ -53,7 +53,7 @@ pub async fn subscribe_anonymous_handler(
basket: Data<Option<Basket>>,
subscription_req: web::Json<SubscriptionRequest>,
) -> Result<HttpResponse, ApiError> {
if let Some(basket) = &**basket {
if let Some(basket) = basket.as_ref() {
basket
.subscribe(
&subscription_req.email,
Expand Down Expand Up @@ -110,7 +110,7 @@ pub async fn unsubscribe_handler(
) -> Result<HttpResponse, ApiError> {
let mut conn = pool.get()?;
let user = get_user(&mut conn, user_id.id()?)?;
if let Some(basket) = &**basket {
if let Some(basket) = basket.as_ref() {
return unsubscribe(&mut conn, &user, basket).await;
}
Ok(HttpResponse::NotImplemented().finish())
Expand Down Expand Up @@ -151,7 +151,7 @@ pub async fn is_subscribed(
) -> Result<HttpResponse, ApiError> {
let mut conn = pool.get()?;
let user = get_user(&mut conn, user_id.id()?)?;
if let Some(basket) = &**basket {
if let Some(basket) = basket.as_ref() {
let value = basket.lookup_user(&user.email).await;
let subscribed = match value {
Ok(value) => {
Expand Down
10 changes: 5 additions & 5 deletions src/api/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static CIPHER: Lazy<Option<Aes256Gcm>> = Lazy::new(|| {
});

fn encrypt(gist_id: &str) -> Result<String, PlaygroundError> {
if let Some(cipher) = &*CIPHER {
if let Some(cipher) = CIPHER.as_ref() {
let mut nonce = vec![0; NONCE_LEN];
OsRng.fill_bytes(&mut nonce);
let nonce = Nonce::from_slice(&nonce);
Expand All @@ -73,7 +73,7 @@ fn encrypt(gist_id: &str) -> Result<String, PlaygroundError> {
}

fn decrypt(encoded: &str) -> Result<String, PlaygroundError> {
if let Some(cipher) = &*CIPHER {
if let Some(cipher) = CIPHER.as_ref() {
let data = STANDARD.decode(encoded)?;
if NONCE_LEN > data.len() {
return Err(PlaygroundError::NoNonceError);
Expand Down Expand Up @@ -166,7 +166,7 @@ pub async fn save(
pool: web::Data<Pool>,
github_client: web::Data<Option<Octocrab>>,
) -> Result<HttpResponse, ApiError> {
if let Some(client) = &**github_client {
if let Some(client) = github_client.as_ref() {
if let Some(user_id) = id {
let gist =
create_gist(client, serde_json::to_string_pretty(&save.into_inner())?).await?;
Expand Down Expand Up @@ -196,7 +196,7 @@ pub async fn load(
gist_id: web::Path<String>,
github_client: web::Data<Option<Octocrab>>,
) -> Result<HttpResponse, ApiError> {
if let Some(client) = &**github_client {
if let Some(client) = github_client.as_ref() {
let id = decrypt(&gist_id.into_inner())?;
let gist = load_gist(client, &id).await?;
Ok(HttpResponse::Ok().json(gist.code))
Expand All @@ -210,7 +210,7 @@ pub async fn flag(
pool: web::Data<Pool>,
github_client: web::Data<Option<Octocrab>>,
) -> Result<HttpResponse, ApiError> {
if let Some(client) = &**github_client {
if let Some(client) = github_client.as_ref() {
let PlayFlagRequest { id, reason } = flag.into_inner();
let gist_id = decrypt(&id)?;
let mut conn = pool.get()?;
Expand Down

0 comments on commit 6119a9d

Please sign in to comment.