From b016a594cc8340ac06cb7d5f2a49fd99c801fa24 Mon Sep 17 00:00:00 2001 From: Scott Schafer Date: Tue, 5 Dec 2023 11:39:46 -0700 Subject: [PATCH] refactor!: Move around items in the public api BREAKING CHANGE: This moves `snippet::*` and `Renderer` to root --- benches/simple.rs | 3 +-- examples/expected_type.rs | 3 +-- examples/footer.rs | 3 +-- examples/format.rs | 3 +-- examples/multislice.rs | 3 +-- src/lib.rs | 12 ++++++++---- src/renderer/mod.rs | 3 +-- src/snippet.rs | 2 +- tests/deserialize/mod.rs | 4 +--- tests/fixtures_test.rs | 4 ++-- tests/formatter.rs | 41 +++++++++++++++++++-------------------- 11 files changed, 38 insertions(+), 43 deletions(-) diff --git a/benches/simple.rs b/benches/simple.rs index 8ccd18f..3a40bbf 100644 --- a/benches/simple.rs +++ b/benches/simple.rs @@ -4,8 +4,7 @@ extern crate criterion; use criterion::{black_box, Criterion}; -use annotate_snippets::renderer::Renderer; -use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation}; +use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation}; fn create_snippet(renderer: Renderer) { let snippet = Snippet { diff --git a/examples/expected_type.rs b/examples/expected_type.rs index 959419c..bbd1fe6 100644 --- a/examples/expected_type.rs +++ b/examples/expected_type.rs @@ -1,5 +1,4 @@ -use annotate_snippets::renderer::Renderer; -use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation}; +use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation}; fn main() { let snippet = Snippet { diff --git a/examples/footer.rs b/examples/footer.rs index 0191c1d..ca02119 100644 --- a/examples/footer.rs +++ b/examples/footer.rs @@ -1,5 +1,4 @@ -use annotate_snippets::renderer::Renderer; -use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation}; +use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation}; fn main() { let snippet = Snippet { diff --git a/examples/format.rs b/examples/format.rs index 7302eef..41f852e 100644 --- a/examples/format.rs +++ b/examples/format.rs @@ -1,5 +1,4 @@ -use annotate_snippets::renderer::Renderer; -use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation}; +use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation}; fn main() { let snippet = Snippet { diff --git a/examples/multislice.rs b/examples/multislice.rs index dc51d4f..63ebb65 100644 --- a/examples/multislice.rs +++ b/examples/multislice.rs @@ -1,5 +1,4 @@ -use annotate_snippets::renderer::Renderer; -use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet}; +use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet}; fn main() { let snippet = Snippet { diff --git a/src/lib.rs b/src/lib.rs index 342db23..5da3575 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,18 +29,22 @@ //! Snippet --> Renderer --> impl Display //! ``` //! -//! The input type - [Snippet](self::snippet) is a structure designed +//! The input type - [Snippet] is a structure designed //! to align with likely output from any parser whose code snippet is to be //! annotated. //! -//! The middle structure - [Renderer](self::renderer) is a structure designed +//! The middle structure - [Renderer] is a structure designed //! to convert a snippet into an internal structure that is designed to store //! the snippet data in a way that is easy to format. -//! [Renderer](self::renderer) also handles the user-configurable formatting +//! [Renderer] also handles the user-configurable formatting //! options, such as color, or margins. //! //! Finally, `impl Display` into a final `String` output. mod display_list; pub mod renderer; -pub mod snippet; +mod snippet; + +#[doc(inline)] +pub use renderer::Renderer; +pub use snippet::*; diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index ce080d3..5f655c8 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -2,8 +2,7 @@ //! //! # Example //! ``` -//! use annotate_snippets::renderer::Renderer; -//! use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet}; +//! use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet}; //! let snippet = Snippet { //! title: Some(Annotation { //! label: Some("mismatched types"), diff --git a/src/snippet.rs b/src/snippet.rs index c1914c9..02e70cc 100644 --- a/src/snippet.rs +++ b/src/snippet.rs @@ -3,7 +3,7 @@ //! Example: //! //! ``` -//! use annotate_snippets::snippet::*; +//! use annotate_snippets::*; //! //! Snippet { //! title: Some(Annotation { diff --git a/tests/deserialize/mod.rs b/tests/deserialize/mod.rs index af959cb..1763005 100644 --- a/tests/deserialize/mod.rs +++ b/tests/deserialize/mod.rs @@ -1,9 +1,7 @@ use serde::{Deserialize, Deserializer, Serialize}; -use annotate_snippets::renderer::Renderer; use annotate_snippets::{ - renderer::Margin, - snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation}, + renderer::Margin, Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation, }; #[derive(Deserialize)] diff --git a/tests/fixtures_test.rs b/tests/fixtures_test.rs index 854719f..063829a 100644 --- a/tests/fixtures_test.rs +++ b/tests/fixtures_test.rs @@ -2,8 +2,8 @@ mod deserialize; mod diff; use crate::deserialize::Fixture; -use annotate_snippets::renderer::Renderer; -use annotate_snippets::snippet::Snippet; +use annotate_snippets::Renderer; +use annotate_snippets::Snippet; use glob::glob; use std::{error::Error, fs::File, io, io::prelude::*}; diff --git a/tests/formatter.rs b/tests/formatter.rs index 3f85b69..97c7be3 100644 --- a/tests/formatter.rs +++ b/tests/formatter.rs @@ -1,23 +1,22 @@ -use annotate_snippets::renderer::Renderer; -use annotate_snippets::snippet::{self, Snippet}; +use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation}; #[test] fn test_i_29() { let snippets = Snippet { - title: Some(snippet::Annotation { + title: Some(Annotation { id: None, label: Some("oops"), - annotation_type: snippet::AnnotationType::Error, + annotation_type: AnnotationType::Error, }), footer: vec![], - slices: vec![snippet::Slice { + slices: vec![Slice { source: "First line\r\nSecond oops line", line_start: 1, origin: Some(""), - annotations: vec![snippet::SourceAnnotation { + annotations: vec![SourceAnnotation { range: (19, 23), label: "oops", - annotation_type: snippet::AnnotationType::Error, + annotation_type: AnnotationType::Error, }], fold: true, }], @@ -37,14 +36,14 @@ fn test_i_29() { #[test] fn test_point_to_double_width_characters() { let snippets = Snippet { - slices: vec![snippet::Slice { + slices: vec![Slice { source: "こんにちは、世界", line_start: 1, origin: Some(""), - annotations: vec![snippet::SourceAnnotation { + annotations: vec![SourceAnnotation { range: (6, 8), label: "world", - annotation_type: snippet::AnnotationType::Error, + annotation_type: AnnotationType::Error, }], fold: false, }], @@ -65,14 +64,14 @@ fn test_point_to_double_width_characters() { #[test] fn test_point_to_double_width_characters_across_lines() { let snippets = Snippet { - slices: vec![snippet::Slice { + slices: vec![Slice { source: "おはよう\nございます", line_start: 1, origin: Some(""), - annotations: vec![snippet::SourceAnnotation { + annotations: vec![SourceAnnotation { range: (2, 8), label: "Good morning", - annotation_type: snippet::AnnotationType::Error, + annotation_type: AnnotationType::Error, }], fold: false, }], @@ -95,20 +94,20 @@ fn test_point_to_double_width_characters_across_lines() { #[test] fn test_point_to_double_width_characters_multiple() { let snippets = Snippet { - slices: vec![snippet::Slice { + slices: vec![Slice { source: "お寿司\n食べたい🍣", line_start: 1, origin: Some(""), annotations: vec![ - snippet::SourceAnnotation { + SourceAnnotation { range: (0, 3), label: "Sushi1", - annotation_type: snippet::AnnotationType::Error, + annotation_type: AnnotationType::Error, }, - snippet::SourceAnnotation { + SourceAnnotation { range: (6, 8), label: "Sushi2", - annotation_type: snippet::AnnotationType::Note, + annotation_type: AnnotationType::Note, }, ], fold: false, @@ -132,14 +131,14 @@ fn test_point_to_double_width_characters_multiple() { #[test] fn test_point_to_double_width_characters_mixed() { let snippets = Snippet { - slices: vec![snippet::Slice { + slices: vec![Slice { source: "こんにちは、新しいWorld!", line_start: 1, origin: Some(""), - annotations: vec![snippet::SourceAnnotation { + annotations: vec![SourceAnnotation { range: (6, 14), label: "New world", - annotation_type: snippet::AnnotationType::Error, + annotation_type: AnnotationType::Error, }], fold: false, }],