Skip to content

Commit

Permalink
refactor(data): Consolidate From impls
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Apr 22, 2024
1 parent e1cadb3 commit bd2a858
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
7 changes: 7 additions & 0 deletions crates/snapbox/src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,13 @@ impl<'s> From<&'s str> for Data {
}
}

impl From<Inline> for super::Data {
fn from(inline: Inline) -> Self {
let trimmed = inline.trimmed();
super::Data::text(trimmed).with_source(inline)
}
}

#[cfg(feature = "detect-encoding")]
fn is_binary(data: &[u8]) -> bool {
match content_inspector::inspect(data) {
Expand Down
9 changes: 1 addition & 8 deletions crates/snapbox/src/data/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub struct Inline {
}

impl Inline {
fn trimmed(&self) -> String {
pub(crate) fn trimmed(&self) -> String {
let mut data = self.data;
if data.contains('\n') {
data = data.strip_prefix('\n').unwrap_or(data);
Expand All @@ -95,13 +95,6 @@ impl std::fmt::Display for Inline {
}
}

impl From<Inline> for super::Data {
fn from(inline: Inline) -> Self {
let trimmed = inline.trimmed();
super::Data::text(trimmed).with_source(inline)
}
}

/// Position within Rust source code, see [`Inline`]
#[doc(hidden)]
#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down

0 comments on commit bd2a858

Please sign in to comment.