case-insensitive UserHandles

This commit is contained in:
2026-02-24 02:06:24 +01:00
parent 1e7866a293
commit fcf43dc0bc
2 changed files with 16 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
CREATE TABLE users ( CREATE TABLE users (
id BLOB NOT NULL UNIQUE PRIMARY KEY, -- UUIDv7 as bytes id BLOB NOT NULL UNIQUE PRIMARY KEY, -- UUIDv7 as bytes
handle TEXT NOT NULL UNIQUE, handle TEXT NOT NULL UNIQUE COLLATE NOCASE,
password TEXT, -- hashed, nullable in case of OAuth2-only login password TEXT, -- hashed, nullable in case of OAuth2-only login
prof_pic TEXT -- link probably prof_pic TEXT -- link probably
); );

View File

@@ -1,4 +1,4 @@
use std::{fmt::Display, ops::Deref, str::FromStr}; use std::{fmt::Display, hash::Hash, ops::Deref, str::FromStr};
use rusqlite::{ use rusqlite::{
Result as RusqliteResult, Result as RusqliteResult,
@@ -6,7 +6,7 @@ use rusqlite::{
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, PartialOrd, Ord)] #[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(into = "String")] #[serde(into = "String")]
#[serde(try_from = "String")] #[serde(try_from = "String")]
pub struct UserHandle(String); pub struct UserHandle(String);
@@ -42,6 +42,19 @@ impl UserHandle {
&self.0 &self.0
} }
} }
impl PartialEq for UserHandle {
fn eq(&self, other: &Self) -> bool {
self.0.eq_ignore_ascii_case(&other.0)
}
}
impl Eq for UserHandle {}
impl Hash for UserHandle {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.0.to_ascii_lowercase().hash(state);
}
}
impl AsRef<str> for UserHandle { impl AsRef<str> for UserHandle {
fn as_ref(&self) -> &str { fn as_ref(&self) -> &str {
&self.0 &self.0