pub enum Suggestion {
PlacePrediction(PlacePrediction),
QueryPrediction(QueryPrediction),
}Expand description
An Autocomplete suggestion result.
Represents a single suggestion from the autocomplete API, which can be either a specific place (like “Pizza Hut, 123 Main St”) or a general query suggestion (like “pizza restaurants near me”). The API may return a mix of both types, allowing users to either navigate to a specific location or explore a broader search query.
§Examples
match suggestion {
Suggestion::PlacePrediction(place) => {
println!("Place: {}", place.text().text());
// Use place.place_id() for Place Details lookup
}
Suggestion::QueryPrediction(query) => {
println!("Query: {}", query.query_string());
// Use query text for search endpoint
}
}
// Format with HTML regardless of type
let html = match &suggestion {
Suggestion::PlacePrediction(p) => p.to_html("strong"),
Suggestion::QueryPrediction(q) => q.to_html("strong"),
};Variants§
PlacePrediction(PlacePrediction)
A prediction for a specific Place.
Represents a concrete location or establishment that the user can navigate to or get details about. Place predictions include identifiers that can be used with other Google Maps APIs.
QueryPrediction(QueryPrediction)
A prediction for a general query.
Represents a search text suggestion that can be used in search endpoints to find relevant places. Query predictions are exploratory and don’t represent specific locations.
Implementations§
Source§impl Suggestion
impl Suggestion
Sourcepub const fn is_place(&self) -> bool
pub const fn is_place(&self) -> bool
Checks if this suggestion is a place prediction.
Returns true if the suggestion represents a specific place rather than a general query.
Sourcepub const fn is_query(&self) -> bool
pub const fn is_query(&self) -> bool
Checks if this suggestion is a query prediction.
Returns true if the suggestion represents a general search query rather than a specific
place.
Sourcepub const fn as_place(&self) -> Option<&PlacePrediction>
pub const fn as_place(&self) -> Option<&PlacePrediction>
Returns a reference to the place prediction if this is a place.
Use this to access place-specific information like place IDs, types, and distance
measurements. Returns None if this is a query prediction.
Sourcepub const fn as_query(&self) -> Option<&QueryPrediction>
pub const fn as_query(&self) -> Option<&QueryPrediction>
Returns a reference to the query prediction if this is a query.
Use this to access query text for search operations. Returns None if this is a place
prediction.
Sourcepub fn text(&self) -> &str
pub fn text(&self) -> &str
Returns the display text for this suggestion.
Extracts the text content regardless of whether this is a place or query prediction. Use this when you need the text without caring about the suggestion type.
Sourcepub fn to_html(&self, tag: &str) -> String
pub fn to_html(&self, tag: &str) -> String
Formats the suggestion text with HTML highlighting.
Applies HTML tags to matched portions regardless of suggestion type. Use this for simple HTML formatting without needing to match on the enum variant.
§Examples
let html = suggestion.to_html("mark");
// "<mark>Pizza</mark> Hut" (for either place or query)Sourcepub fn to_html_structured(&self, main_tag: &str, secondary_tag: &str) -> String
pub fn to_html_structured(&self, main_tag: &str, secondary_tag: &str) -> String
Formats the suggestion with structured HTML if available.
Applies different HTML tags to main and secondary text portions if structured format is available. Otherwise, falls back to highlighting the full text with the main tag. Works for both place and query predictions.
§Examples
let html = suggestion.to_html_structured("strong", "em");
// "<strong>Pizza</strong> Hut, <em>123 Main</em> St"Sourcepub fn place_id(&self) -> Option<&str>
pub fn place_id(&self) -> Option<&str>
Returns the Place ID associated with the suggestion, if any.
- If the suggestion is a a place prediction this will return
Some - If it’s a query prediction it will return
None
Sourcepub fn format_with<F>(&self, formatter: F) -> String
pub fn format_with<F>(&self, formatter: F) -> String
Formats the suggestion with a custom formatter function.
Applies a custom formatting function to the text, distinguishing between matched and unmatched portions. Works for both place and query predictions, providing maximum flexibility for any output format (ANSI, Markdown, etc.).
§Examples
ANSI terminal colors:
let formatted = suggestion.format_with(|text, is_matched| {
if is_matched {
format!("\x1b[1;32m{}\x1b[0m", text) // Bold green
} else {
text.to_string()
}
});Markdown:
let formatted = suggestion.format_with(|text, is_matched| {
if is_matched {
format!("**{}**", text)
} else {
text.to_string()
}
});Sourcepub fn format_with_structured<F, G>(
&self,
main_formatter: F,
secondary_formatter: G,
) -> String
pub fn format_with_structured<F, G>( &self, main_formatter: F, secondary_formatter: G, ) -> String
Formats with custom formatters using structured format if available.
Applies different formatting functions to main and secondary text if structured format exists. Works for both place and query predictions. Falls back to the main formatter only if structured format is not available.
§Examples
ANSI terminal colors:
let formatted = suggestion.format_with_structured(
|text, is_matched| {
if is_matched {
format!("\x1b[1;33m{}\x1b[0m", text) // Bold yellow
} else {
text.to_string()
}
},
|text, is_matched| {
if is_matched {
format!("\x1b[36m{}\x1b[0m", text) // Cyan
} else {
text.to_string()
}
}
);Trait Implementations§
Source§impl Clone for Suggestion
impl Clone for Suggestion
Source§fn clone(&self) -> Suggestion
fn clone(&self) -> Suggestion
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Suggestion
impl Debug for Suggestion
Source§impl<'de> Deserialize<'de> for Suggestion
impl<'de> Deserialize<'de> for Suggestion
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for Suggestion
impl Display for Suggestion
Source§impl From<PlacePrediction> for Suggestion
impl From<PlacePrediction> for Suggestion
Source§fn from(place: PlacePrediction) -> Self
fn from(place: PlacePrediction) -> Self
Converts a PlacePrediction to a Suggestion.
Wraps a place prediction in the suggestion enum. Use this for convenience when constructing suggestion lists.
Source§impl From<QueryPrediction> for Suggestion
impl From<QueryPrediction> for Suggestion
Source§fn from(query: QueryPrediction) -> Self
fn from(query: QueryPrediction) -> Self
Converts a QueryPrediction to a Suggestion.
Wraps a query prediction in the suggestion enum. Use this for convenience when constructing suggestion lists.
Source§impl PartialEq for Suggestion
impl PartialEq for Suggestion
Source§impl Serialize for Suggestion
impl Serialize for Suggestion
impl Eq for Suggestion
impl StructuralPartialEq for Suggestion
Auto Trait Implementations§
impl Freeze for Suggestion
impl RefUnwindSafe for Suggestion
impl Send for Suggestion
impl Sync for Suggestion
impl Unpin for Suggestion
impl UnsafeUnpin for Suggestion
impl UnwindSafe for Suggestion
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.