From 24511ae5f10e6b13f847945f89877b0c381b9381 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Thu, 1 Sep 2016 11:49:47 -0700 Subject: [PATCH] Accept `Into` in `EditView::set_content` --- src/views/edit_view.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/views/edit_view.rs b/src/views/edit_view.rs index c886498..bf5f6d0 100644 --- a/src/views/edit_view.rs +++ b/src/views/edit_view.rs @@ -165,10 +165,13 @@ impl EditView { } /// Replace the entire content of the view with the given one. - pub fn set_content(&mut self, content: &str) { - self.content = Rc::new(content.to_string()); + pub fn set_content>(&mut self, content: S) { + let content = content.into(); + let len = content.len(); + + self.content = Rc::new(content); self.offset = 0; - self.set_cursor(content.len()); + self.set_cursor(len); } /// Get the current text. @@ -179,7 +182,7 @@ impl EditView { /// Sets the current content to the given value. /// /// Convenient chainable method. - pub fn content(mut self, content: &str) -> Self { + pub fn content>(mut self, content: S) -> Self { self.set_content(content); self }