Skip to content

Commit

Permalink
prefer eliding lifetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Dec 1, 2024
1 parent 7f27222 commit fa64c50
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
10 changes: 5 additions & 5 deletions examples/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct SearchBox<'a> {
open: bool,
}

impl<'a> Default for SearchBox<'a> {
impl Default for SearchBox<'_> {
fn default() -> Self {
let mut textarea = TextArea::default();
textarea.set_block(Block::default().borders(Borders::ALL).title("Search"));
Expand All @@ -39,7 +39,7 @@ impl<'a> Default for SearchBox<'a> {
}
}

impl<'a> SearchBox<'a> {
impl SearchBox<'_> {
fn open(&mut self) {
self.open = true;
}
Expand Down Expand Up @@ -96,7 +96,7 @@ struct Buffer<'a> {
modified: bool,
}

impl<'a> Buffer<'a> {
impl Buffer<'_> {
fn new(path: PathBuf) -> io::Result<Self> {
let mut textarea = if let Ok(md) = path.metadata() {
if md.is_file() {
Expand Down Expand Up @@ -143,7 +143,7 @@ struct Editor<'a> {
search: SearchBox<'a>,
}

impl<'a> Editor<'a> {
impl Editor<'_> {
fn new<I>(paths: I) -> io::Result<Self>
where
I: Iterator,
Expand Down Expand Up @@ -348,7 +348,7 @@ impl<'a> Editor<'a> {
}
}

impl<'a> Drop for Editor<'a> {
impl Drop for Editor<'_> {
fn drop(&mut self) {
self.term.show_cursor().unwrap();
disable_raw_mode().unwrap();
Expand Down
6 changes: 3 additions & 3 deletions src/textarea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub struct TextArea<'a> {
/// let textarea = TextArea::from(slice.iter().copied());
/// assert_eq!(textarea.lines(), ["hello", "world"]);
/// ```
impl<'a, I> From<I> for TextArea<'a>
impl<I> From<I> for TextArea<'_>
where
I: IntoIterator,
I::Item: Into<String>,
Expand All @@ -174,7 +174,7 @@ where
/// let textarea = read_from_file("README.md").unwrap();
/// assert!(!textarea.is_empty());
/// ```
impl<'a, S: Into<String>> FromIterator<S> for TextArea<'a> {
impl<S: Into<String>> FromIterator<S> for TextArea<'_> {
fn from_iter<I: IntoIterator<Item = S>>(iter: I) -> Self {
iter.into()
}
Expand All @@ -188,7 +188,7 @@ impl<'a, S: Into<String>> FromIterator<S> for TextArea<'a> {
/// assert_eq!(textarea.lines(), [""]);
/// assert!(textarea.is_empty());
/// ```
impl<'a> Default for TextArea<'a> {
impl Default for TextArea<'_> {
fn default() -> Self {
Self::new(vec![String::new()])
}
Expand Down
24 changes: 8 additions & 16 deletions tests/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@ fn back() {

#[test]
fn up() {
for text in [
["abc", "def", "ghi"],
["あいう", "🐶🐱🐰", "👪🤟🏿👩🏻‍❤️‍💋‍👨🏾"],
] {
for text in [["abc", "def", "ghi"], ["あいう", "🐶🐱🐰", "👪🤟🏿👩🏻‍❤️‍💋‍👨🏾"]]
{
let mut t = TextArea::from(text);

for col in 0..=3 {
Expand Down Expand Up @@ -146,10 +144,8 @@ fn up_trim() {

#[test]
fn down() {
for text in [
["abc", "def", "ghi"],
["あいう", "🐶🐱🐰", "👪🤟🏿👩🏻‍❤️‍💋‍👨🏾"],
] {
for text in [["abc", "def", "ghi"], ["あいう", "🐶🐱🐰", "👪🤟🏿👩🏻‍❤️‍💋‍👨🏾"]]
{
let mut t = TextArea::from(text);

for col in 0..=3 {
Expand Down Expand Up @@ -217,10 +213,8 @@ fn end() {

#[test]
fn top() {
for text in [
["abc", "def", "ghi"],
["あいう", "🐶🐱🐰", "👪🤟🏿👩🏻‍❤️‍💋‍👨🏾"],
] {
for text in [["abc", "def", "ghi"], ["あいう", "🐶🐱🐰", "👪🤟🏿👩🏻‍❤️‍💋‍👨🏾"]]
{
let mut t = TextArea::from(text);
for row in 0..=2 {
for col in 0..=3 {
Expand Down Expand Up @@ -250,10 +244,8 @@ fn top_trim() {

#[test]
fn bottom() {
for text in [
["abc", "def", "ghi"],
["あいう", "🐶🐱🐰", "👪🤟🏿👩🏻‍❤️‍💋‍👨🏾"],
] {
for text in [["abc", "def", "ghi"], ["あいう", "🐶🐱🐰", "👪🤟🏿👩🏻‍❤️‍💋‍👨🏾"]]
{
let mut t = TextArea::from(text);
for row in 0..=2 {
for col in 0..=3 {
Expand Down

0 comments on commit fa64c50

Please # to comment.