Skip to content

Commit

Permalink
remove phantom!
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeisler committed Sep 26, 2020
1 parent a52bd44 commit 41418a7
Showing 1 changed file with 19 additions and 27 deletions.
46 changes: 19 additions & 27 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ pub use crate::indentation::indent;
mod splitting;
pub use crate::splitting::{HyphenSplitter, NoHyphenation, WordSplitter};

pub trait WrapOptions<'indent> {
pub trait WrapOptions {
fn width(&self) -> usize;
fn initial_indent(&self) -> &'indent str;
fn subsequent_indent(&self) -> &'indent str;
fn initial_indent(&self) -> &str;
fn subsequent_indent(&self) -> &str;
fn break_words(&self) -> bool;
fn split<'w>(&self, word: &'w str) -> Vec<(&'w str, &'w str, &'w str)>;
}
Expand All @@ -143,14 +143,14 @@ pub struct Options<'a> {
pub splitter: Box<dyn WordSplitter>,
}

impl<'indent> WrapOptions<'indent> for Options<'indent> {
impl<'indent> WrapOptions for Options<'indent> {
fn width(&self) -> usize {
self.width
}
fn initial_indent(&self) -> &'indent str {
fn initial_indent(&self) -> &str {
self.initial_indent
}
fn subsequent_indent(&self) -> &'indent str {
fn subsequent_indent(&self) -> &str {
self.subsequent_indent
}
fn break_words(&self) -> bool {
Expand All @@ -161,17 +161,17 @@ impl<'indent> WrapOptions<'indent> for Options<'indent> {
}
}

impl<'indent> WrapOptions<'indent> for &Options<'indent> {
impl<'indent> WrapOptions for &Options<'indent> {
#[inline]
fn width(&self) -> usize {
self.width
}
#[inline]
fn initial_indent(&self) -> &'indent str {
fn initial_indent(&self) -> &str {
self.initial_indent
}
#[inline]
fn subsequent_indent(&self) -> &'indent str {
fn subsequent_indent(&self) -> &str {
self.subsequent_indent
}
#[inline]
Expand All @@ -184,17 +184,17 @@ impl<'indent> WrapOptions<'indent> for &Options<'indent> {
}
}

impl<'a> WrapOptions<'a> for usize {
impl WrapOptions for usize {
#[inline]
fn width(&self) -> usize {
*self
}
#[inline]
fn initial_indent(&self) -> &'a str {
fn initial_indent(&self) -> &str {
""
}
#[inline]
fn subsequent_indent(&self) -> &'a str {
fn subsequent_indent(&self) -> &str {
""
}
#[inline]
Expand Down Expand Up @@ -337,11 +337,9 @@ fn is_whitespace(ch: char) -> bool {

/// An iterator which borrows a `Options`.
#[derive(Debug)]
struct WrapIter<'indent, 'input: 'indent, T: WrapOptions<'indent>> {
struct WrapIter<'input, T: WrapOptions> {
options: T,

phantom: std::marker::PhantomData<&'indent str>,

// String to wrap.
source: &'input str,
// CharIndices iterator over self.source.
Expand All @@ -362,8 +360,8 @@ struct WrapIter<'indent, 'input: 'indent, T: WrapOptions<'indent>> {
finished: bool,
}

impl<'indent, 'input: 'indent, T: WrapOptions<'indent>> WrapIter<'indent, 'input, T> {
fn new(options: T, s: &'input str) -> WrapIter<'indent, 'input, T> {
impl<'indent, 'input: 'indent, T: WrapOptions> WrapIter<'input, T> {
fn new(options: T, s: &'input str) -> WrapIter<'input, T> {
let initial_indent_width = options.initial_indent().width();

WrapIter {
Expand All @@ -377,7 +375,6 @@ impl<'indent, 'input: 'indent, T: WrapOptions<'indent>> WrapIter<'indent, 'input
line_width_at_split: initial_indent_width,
in_whitespace: false,
finished: false,
phantom: std::marker::PhantomData,
}
}

Expand All @@ -398,9 +395,7 @@ impl<'indent, 'input: 'indent, T: WrapOptions<'indent>> WrapIter<'indent, 'input
}
}

impl<'indent, 'input: 'indent, T: 'indent + WrapOptions<'indent>> Iterator
for WrapIter<'indent, 'input, T>
{
impl<'indent, 'input: 'indent, T: 'indent + WrapOptions> Iterator for WrapIter<'input, T> {
type Item = Cow<'input, str>;

fn next(&mut self) -> Option<Cow<'input, str>> {
Expand Down Expand Up @@ -588,7 +583,7 @@ pub fn termwidth() -> usize {
/// [`fill` method]: struct.Options.html#method.fill
pub fn fill<'indent, 'input: 'indent, T>(text: &'input str, options: T) -> String
where
T: 'indent + WrapOptions<'indent>,
T: 'indent + WrapOptions,
{
// This will avoid reallocation in simple cases (no
// indentation, no hyphenation).
Expand Down Expand Up @@ -627,13 +622,10 @@ where
///
/// [`wrap_iter`]: struct.Options.html#method.wrap_iter
/// [`into_wrap_iter`]: struct.Options.html#method.into_wrap_iter
pub fn wrap<'indent, 'input: 'indent, T>(
pub fn wrap<'indent, 'input: 'indent, T: 'indent + WrapOptions>(
text: &'input str,
options: T,
) -> impl Iterator<Item = Cow<'input, str>> + 'indent
where
T: 'indent + WrapOptions<'indent>,
{
) -> impl Iterator<Item = Cow<'input, str>> + 'indent {
WrapIter::new(options, text)
}

Expand Down

0 comments on commit 41418a7

Please sign in to comment.