Skip to content

Commit bbf9c5f

Browse files
committed
fix!: Rename SourceAnnotation to Annotation
1 parent b49f947 commit bbf9c5f

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

src/snippet.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ impl<'a> Label<'a> {
100100
self
101101
}
102102

103-
/// Create a [`SourceAnnotation`] with the given span for a [`Slice`]
104-
pub fn span(&self, span: Range<usize>) -> SourceAnnotation<'a> {
105-
SourceAnnotation {
103+
/// Create a [`Annotation`] with the given span for a [`Slice`]
104+
pub fn span(&self, span: Range<usize>) -> Annotation<'a> {
105+
Annotation {
106106
range: span,
107107
label: self.label,
108108
level: self.level,
@@ -119,7 +119,7 @@ pub struct Slice<'a> {
119119
pub(crate) source: &'a str,
120120
pub(crate) line_start: usize,
121121
pub(crate) origin: Option<&'a str>,
122-
pub(crate) annotations: Vec<SourceAnnotation<'a>>,
122+
pub(crate) annotations: Vec<Annotation<'a>>,
123123
pub(crate) fold: bool,
124124
}
125125

@@ -139,7 +139,7 @@ impl<'a> Slice<'a> {
139139
self
140140
}
141141

142-
pub fn annotation(mut self, annotation: SourceAnnotation<'a>) -> Self {
142+
pub fn annotation(mut self, annotation: Annotation<'a>) -> Self {
143143
self.annotations.push(annotation);
144144
self
145145
}
@@ -166,7 +166,7 @@ pub enum Level {
166166
///
167167
/// This gets created by [`Label::span`].
168168
#[derive(Debug)]
169-
pub struct SourceAnnotation<'a> {
169+
pub struct Annotation<'a> {
170170
/// The byte range of the annotation in the `source` string
171171
pub(crate) range: Range<usize>,
172172
pub(crate) label: &'a str,

tests/fixtures/deserialize.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use serde::{Deserialize, Deserializer, Serialize};
22
use std::ops::Range;
33

4-
use annotate_snippets::{
5-
renderer::Margin, Label, Level, Renderer, Slice, Snippet, SourceAnnotation,
6-
};
4+
use annotate_snippets::{renderer::Margin, Annotation, Label, Level, Renderer, Slice, Snippet};
75

86
#[derive(Deserialize)]
97
pub struct Fixture<'a> {
@@ -105,9 +103,9 @@ pub struct SliceDef<'a> {
105103
pub line_start: usize,
106104
#[serde(borrow)]
107105
pub origin: Option<&'a str>,
108-
#[serde(deserialize_with = "deserialize_source_annotations")]
106+
#[serde(deserialize_with = "deserialize_annotations")]
109107
#[serde(borrow)]
110-
pub annotations: Vec<SourceAnnotation<'a>>,
108+
pub annotations: Vec<Annotation<'a>>,
111109
#[serde(default)]
112110
pub fold: bool,
113111
}
@@ -132,31 +130,29 @@ impl<'a> From<SliceDef<'a>> for Slice<'a> {
132130
}
133131
}
134132

135-
fn deserialize_source_annotations<'de, D>(
136-
deserializer: D,
137-
) -> Result<Vec<SourceAnnotation<'de>>, D::Error>
133+
fn deserialize_annotations<'de, D>(deserializer: D) -> Result<Vec<Annotation<'de>>, D::Error>
138134
where
139135
D: Deserializer<'de>,
140136
{
141137
#[derive(Deserialize)]
142-
struct Wrapper<'a>(#[serde(borrow)] SourceAnnotationDef<'a>);
138+
struct Wrapper<'a>(#[serde(borrow)] AnnotationDef<'a>);
143139

144140
let v = Vec::deserialize(deserializer)?;
145141
Ok(v.into_iter().map(|Wrapper(a)| a.into()).collect())
146142
}
147143

148144
#[derive(Serialize, Deserialize)]
149-
pub struct SourceAnnotationDef<'a> {
145+
pub struct AnnotationDef<'a> {
150146
pub range: Range<usize>,
151147
#[serde(borrow)]
152148
pub label: &'a str,
153149
#[serde(with = "LevelDef")]
154150
pub level: Level,
155151
}
156152

157-
impl<'a> From<SourceAnnotationDef<'a>> for SourceAnnotation<'a> {
158-
fn from(val: SourceAnnotationDef<'a>) -> Self {
159-
let SourceAnnotationDef {
153+
impl<'a> From<AnnotationDef<'a>> for Annotation<'a> {
154+
fn from(val: AnnotationDef<'a>) -> Self {
155+
let AnnotationDef {
160156
range,
161157
label,
162158
level,

0 commit comments

Comments
 (0)