summaryrefslogtreecommitdiffstats
path: root/third_party/rust/suggest/src/suggestion.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/suggest/src/suggestion.rs')
-rw-r--r--third_party/rust/suggest/src/suggestion.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/third_party/rust/suggest/src/suggestion.rs b/third_party/rust/suggest/src/suggestion.rs
index f5425e3c73..c0b45524c7 100644
--- a/third_party/rust/suggest/src/suggestion.rs
+++ b/third_party/rust/suggest/src/suggestion.rs
@@ -29,6 +29,7 @@ pub enum Suggestion {
url: String,
raw_url: String,
icon: Option<Vec<u8>>,
+ icon_mimetype: Option<String>,
full_keyword: String,
block_id: i64,
advertiser: String,
@@ -48,6 +49,7 @@ pub enum Suggestion {
title: String,
url: String,
icon: Option<Vec<u8>>,
+ icon_mimetype: Option<String>,
full_keyword: String,
},
Amo {
@@ -64,6 +66,7 @@ pub enum Suggestion {
url: String,
title: String,
icon: Option<Vec<u8>>,
+ icon_mimetype: Option<String>,
score: f64,
has_location_sign: bool,
subject_exact_match: bool,
@@ -106,6 +109,37 @@ impl Ord for Suggestion {
}
}
+impl Suggestion {
+ /// Get the URL for this suggestion, if present
+ pub fn url(&self) -> Option<&str> {
+ match self {
+ Self::Amp { url, .. }
+ | Self::Pocket { url, .. }
+ | Self::Wikipedia { url, .. }
+ | Self::Amo { url, .. }
+ | Self::Yelp { url, .. }
+ | Self::Mdn { url, .. } => Some(url),
+ _ => None,
+ }
+ }
+
+ /// Get the raw URL for this suggestion, if present
+ ///
+ /// This is the same as `url` except for Amp. In that case, `url` is the URL after being
+ /// "cooked" using template interpolation, while `raw_url` is the URL template.
+ pub fn raw_url(&self) -> Option<&str> {
+ match self {
+ Self::Amp { raw_url: url, .. }
+ | Self::Pocket { url, .. }
+ | Self::Wikipedia { url, .. }
+ | Self::Amo { url, .. }
+ | Self::Yelp { url, .. }
+ | Self::Mdn { url, .. } => Some(url),
+ _ => None,
+ }
+ }
+}
+
impl Eq for Suggestion {}
/// Replaces all template parameters in a "raw" sponsored suggestion URL,
/// producing a "cooked" URL with real values.