/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use std::borrow::Cow; use rusqlite::{ types::{FromSql, FromSqlResult, ToSqlOutput, ValueRef}, ToSql, }; #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct Key(String); impl<'a> From> for Key { fn from(key: Cow<'a, str>) -> Self { Self(key.into_owned()) } } impl From<&str> for Key { fn from(key: &str) -> Self { Self(key.to_owned()) } } impl Key { pub fn as_str(&self) -> &str { &self.0 } pub fn into_string(self) -> String { self.0 } } impl ToSql for Key { fn to_sql(&self) -> rusqlite::Result> { Ok(ToSqlOutput::from(self.0.as_str())) } } impl FromSql for Key { fn column_result(value: ValueRef<'_>) -> FromSqlResult { Ok(Self(String::column_result(value)?)) } }