summaryrefslogtreecommitdiffstats
path: root/third_party/rust/suggest/src/provider.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/rust/suggest/src/provider.rs
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/suggest/src/provider.rs')
-rw-r--r--third_party/rust/suggest/src/provider.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/third_party/rust/suggest/src/provider.rs b/third_party/rust/suggest/src/provider.rs
new file mode 100644
index 0000000000..1449c35c8a
--- /dev/null
+++ b/third_party/rust/suggest/src/provider.rs
@@ -0,0 +1,55 @@
+/* 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 rusqlite::{
+ types::{FromSql, FromSqlError, FromSqlResult, ToSql, ToSqlOutput, ValueRef},
+ Result as RusqliteResult,
+};
+
+/// A provider is a source of search suggestions.
+#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
+#[repr(u8)]
+pub enum SuggestionProvider {
+ Amp = 1,
+ Wikipedia = 2,
+ Amo = 3,
+ Pocket = 4,
+ Yelp = 5,
+ Mdn = 6,
+ Weather = 7,
+ AmpMobile = 8,
+}
+
+impl FromSql for SuggestionProvider {
+ fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self> {
+ let v = value.as_i64()?;
+ u8::try_from(v)
+ .ok()
+ .and_then(SuggestionProvider::from_u8)
+ .ok_or_else(|| FromSqlError::OutOfRange(v))
+ }
+}
+
+impl SuggestionProvider {
+ #[inline]
+ pub(crate) fn from_u8(v: u8) -> Option<Self> {
+ match v {
+ 1 => Some(SuggestionProvider::Amp),
+ 2 => Some(SuggestionProvider::Wikipedia),
+ 3 => Some(SuggestionProvider::Amo),
+ 4 => Some(SuggestionProvider::Pocket),
+ 5 => Some(SuggestionProvider::Yelp),
+ 6 => Some(SuggestionProvider::Mdn),
+ 7 => Some(SuggestionProvider::Weather),
+ _ => None,
+ }
+ }
+}
+
+impl ToSql for SuggestionProvider {
+ fn to_sql(&self) -> RusqliteResult<ToSqlOutput<'_>> {
+ Ok(ToSqlOutput::from(*self as u8))
+ }
+}