Skip to content

Enforce Rust 2018 idioms #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/formatter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn repeat_char(c: char, n: usize) -> String {
/// assert_eq!(dlf.format(&dl), "192 | Example line of text");
/// ```
pub struct DisplayListFormatter {
stylesheet: Box<Stylesheet>,
stylesheet: Box<dyn Stylesheet>,
}

impl DisplayListFormatter {
Expand Down Expand Up @@ -101,7 +101,7 @@ impl DisplayListFormatter {
}
}

fn get_annotation_style(&self, annotation_type: &DisplayAnnotationType) -> Box<Style> {
fn get_annotation_style(&self, annotation_type: &DisplayAnnotationType) -> Box<dyn Style> {
self.stylesheet.get_style(match annotation_type {
DisplayAnnotationType::Error => StyleClass::Error,
DisplayAnnotationType::Warning => StyleClass::Warning,
Expand Down
4 changes: 2 additions & 2 deletions src/formatter/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ pub trait Style {
fn paint(&self, text: &str) -> String;
/// The method used by the DisplayListFormatter to display the message
/// in bold font.
fn bold(&self) -> Box<Style>;
fn bold(&self) -> Box<dyn Style>;
}

/// Trait to annotate structs that can provide `Style` implementations for
/// every `StyleClass` variant.
pub trait Stylesheet {
/// Returns a `Style` implementer based on the requested `StyleClass` variant.
fn get_style(&self, class: StyleClass) -> Box<Style>;
fn get_style(&self, class: StyleClass) -> Box<dyn Style>;
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(rust_2018_idioms)]

//! A library for formatting of text or programming code snippets.
//!
//! It's primary purpose is to build an ASCII-graphical representation of the snippet
Expand Down
4 changes: 2 additions & 2 deletions src/stylesheets/no_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ impl Style for NoOpStyle {
text.to_string()
}

fn bold(&self) -> Box<Style> {
fn bold(&self) -> Box<dyn Style> {
Box::new(NoOpStyle {})
}
}

pub struct NoColorStylesheet {}

impl Stylesheet for NoColorStylesheet {
fn get_style(&self, _class: StyleClass) -> Box<Style> {
fn get_style(&self, _class: StyleClass) -> Box<dyn Style> {
Box::new(NoOpStyle {})
}
}