#[non_exhaustive]pub enum Annotation {
UrlCitation {
url: Option<String>,
title: Option<String>,
start_index: usize,
end_index: usize,
},
FileCitation {
document_uri: Option<String>,
file_name: Option<String>,
source: Option<String>,
custom_metadata: Option<Value>,
page_number: Option<u32>,
media_id: Option<String>,
start_index: usize,
end_index: usize,
},
PlaceCitation {
place_id: Option<String>,
name: Option<String>,
url: Option<String>,
review_snippets: Vec<ReviewSnippet>,
start_index: usize,
end_index: usize,
},
Unknown {
annotation_type: String,
data: Value,
},
}Expand description
A citation annotation attached to text content.
Annotations link byte ranges of the text (start_index..end_index,
UTF-8 byte offsets) to their sources. Revision 2026-05-20 uses a
discriminated union over type: url_citation, file_citation, and
place_citation.
§Forward Compatibility
#[non_exhaustive]; unrecognized annotation types deserialize into
Annotation::Unknown with the full JSON preserved.
§Example
let text = response.all_text();
for annotation in response.all_annotations() {
match annotation {
Annotation::UrlCitation { url, title, .. } => {
println!("Source: {:?} ({:?})", title, url);
}
Annotation::Unknown { annotation_type, .. } => {
println!("Unknown annotation type: {}", annotation_type);
}
_ => {}
}
if let Some(span) = annotation.extract_span(&text) {
println!(" Cited text: {}", span);
}
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
UrlCitation
A citation of a web source (type: "url_citation").
Fields
FileCitation
A citation of an uploaded/retrieved document (type: "file_citation").
Fields
PlaceCitation
A citation of a Google Maps place (type: "place_citation").
Fields
review_snippets: Vec<ReviewSnippet>Review snippets supporting the citation.
Unknown
Unknown annotation type for forward compatibility.
Implementations§
Source§impl Annotation
impl Annotation
Sourcepub fn url_citation(
url: impl Into<String>,
title: Option<String>,
start_index: usize,
end_index: usize,
) -> Self
pub fn url_citation( url: impl Into<String>, title: Option<String>, start_index: usize, end_index: usize, ) -> Self
Creates a URL citation annotation.
Sourcepub const fn is_unknown(&self) -> bool
pub const fn is_unknown(&self) -> bool
Check if this is an unknown annotation type.
Sourcepub fn unknown_annotation_type(&self) -> Option<&str>
pub fn unknown_annotation_type(&self) -> Option<&str>
Returns the annotation type name if this is an unknown annotation.
Sourcepub fn unknown_data(&self) -> Option<&Value>
pub fn unknown_data(&self) -> Option<&Value>
Returns the raw JSON data if this is an unknown annotation.
Sourcepub fn start_index(&self) -> Option<usize>
pub fn start_index(&self) -> Option<usize>
Start of the annotated span (UTF-8 byte offset, inclusive).
Returns None for Annotation::Unknown without a numeric
start_index field.
Sourcepub fn end_index(&self) -> Option<usize>
pub fn end_index(&self) -> Option<usize>
End of the annotated span (UTF-8 byte offset, exclusive).
Sourcepub fn source(&self) -> Option<&str>
pub fn source(&self) -> Option<&str>
Returns the primary source identifier for this annotation, if any.
url_citation→ the URLfile_citation→ the document URI (or file name)place_citation→ the place URL (or place ID)
Sourcepub fn extract_span<'a>(&self, text: &'a str) -> Option<&'a str>
pub fn extract_span<'a>(&self, text: &'a str) -> Option<&'a str>
Extracts the annotated substring from the given text.
Returns None if the indices are missing, out of bounds, or don’t
fall on valid UTF-8 boundaries.
§Example
let annotation = Annotation::url_citation("https://example.com", None, 0, 5);
assert_eq!(annotation.extract_span("Hello, world!"), Some("Hello"));Trait Implementations§
Source§impl Clone for Annotation
impl Clone for Annotation
Source§impl Debug for Annotation
impl Debug for Annotation
Source§impl<'de> Deserialize<'de> for Annotation
impl<'de> Deserialize<'de> for Annotation
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 PartialEq for Annotation
impl PartialEq for Annotation
Source§impl Serialize for Annotation
impl Serialize for Annotation
impl StructuralPartialEq for Annotation
Auto Trait Implementations§
impl Freeze for Annotation
impl RefUnwindSafe for Annotation
impl Send for Annotation
impl Sync for Annotation
impl Unpin for Annotation
impl UnsafeUnpin for Annotation
impl UnwindSafe for Annotation
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);