Skip to content

Commit

Permalink
impl repr
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshix-1 committed Oct 16, 2024
1 parent 651f7b6 commit 929d974
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/language/word_sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,31 @@ impl WordSequence {
false
}
}

#[must_use]
pub fn __repr__(&self) -> String {
const START: &str = "['";
const SEPERATOR: &str = "', '";
const END: &str = "']";

const _: () = assert!(SEPERATOR.len() == START.len() + END.len());

let mut data = String::with_capacity(
self.data.len() + SEPERATOR.len() * self.len(),
);
data.push_str(START);

let mut iter = self.iter();
while let Some(word) = iter.next() {
data.push_str(word);
if iter.__len__() > 0 {
data.push_str(SEPERATOR);
}
}

data.push_str(END);

data.shrink_to_fit();
data
}
}

0 comments on commit 929d974

Please sign in to comment.