refactor: impl method returns Self
This commit is contained in:
+2
-2
@@ -20,8 +20,8 @@ struct App<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> App<'a> {
|
impl<'a> App<'a> {
|
||||||
fn new() -> App<'a> {
|
fn new() -> Self {
|
||||||
App {
|
Self {
|
||||||
tree: StatefulTree::with_items(vec![
|
tree: StatefulTree::with_items(vec![
|
||||||
TreeItem::new_leaf("a"),
|
TreeItem::new_leaf("a"),
|
||||||
TreeItem::new(
|
TreeItem::new(
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ pub struct Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
fn default() -> Config {
|
fn default() -> Self {
|
||||||
Config {
|
Self {
|
||||||
exit_key: Key::Char('q'),
|
exit_key: Key::Char('q'),
|
||||||
tick_rate: Duration::from_millis(250),
|
tick_rate: Duration::from_millis(250),
|
||||||
}
|
}
|
||||||
@@ -34,11 +34,11 @@ impl Default for Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Events {
|
impl Events {
|
||||||
pub fn new() -> Events {
|
pub fn new() -> Self {
|
||||||
Events::with_config(Config::default())
|
Self::with_config(Config::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_config(config: Config) -> Events {
|
pub fn with_config(config: Config) -> Self {
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
{
|
{
|
||||||
let tx = tx.clone();
|
let tx = tx.clone();
|
||||||
@@ -63,7 +63,7 @@ impl Events {
|
|||||||
}
|
}
|
||||||
thread::sleep(config.tick_rate);
|
thread::sleep(config.tick_rate);
|
||||||
});
|
});
|
||||||
Events { rx }
|
Self { rx }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next(&self) -> Result<Event<Key>, mpsc::RecvError> {
|
pub fn next(&self) -> Result<Event<Key>, mpsc::RecvError> {
|
||||||
|
|||||||
@@ -9,15 +9,15 @@ pub struct StatefulTree<'a> {
|
|||||||
|
|
||||||
impl<'a> StatefulTree<'a> {
|
impl<'a> StatefulTree<'a> {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn new() -> StatefulTree<'a> {
|
pub fn new() -> Self {
|
||||||
StatefulTree {
|
Self {
|
||||||
state: TreeState::default(),
|
state: TreeState::default(),
|
||||||
items: Vec::new(),
|
items: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_items(items: Vec<TreeItem<'a>>) -> StatefulTree<'a> {
|
pub fn with_items(items: Vec<TreeItem<'a>>) -> Self {
|
||||||
StatefulTree {
|
Self {
|
||||||
state: TreeState::default(),
|
state: TreeState::default(),
|
||||||
items,
|
items,
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-14
@@ -23,8 +23,8 @@ pub struct TreeState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Default for TreeState {
|
impl Default for TreeState {
|
||||||
fn default() -> TreeState {
|
fn default() -> Self {
|
||||||
TreeState {
|
Self {
|
||||||
offset: 0,
|
offset: 0,
|
||||||
selected: Vec::new(),
|
selected: Vec::new(),
|
||||||
opened: HashSet::new(),
|
opened: HashSet::new(),
|
||||||
@@ -82,23 +82,23 @@ pub struct TreeItem<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> TreeItem<'a> {
|
impl<'a> TreeItem<'a> {
|
||||||
pub fn new_leaf<T>(text: T) -> TreeItem<'a>
|
pub fn new_leaf<T>(text: T) -> Self
|
||||||
where
|
where
|
||||||
T: Into<Text<'a>>,
|
T: Into<Text<'a>>,
|
||||||
{
|
{
|
||||||
TreeItem {
|
Self {
|
||||||
text: text.into(),
|
text: text.into(),
|
||||||
style: Style::default(),
|
style: Style::default(),
|
||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new<T, Children>(text: T, children: Children) -> TreeItem<'a>
|
pub fn new<T, Children>(text: T, children: Children) -> Self
|
||||||
where
|
where
|
||||||
T: Into<Text<'a>>,
|
T: Into<Text<'a>>,
|
||||||
Children: Into<Vec<TreeItem<'a>>>,
|
Children: Into<Vec<TreeItem<'a>>>,
|
||||||
{
|
{
|
||||||
TreeItem {
|
Self {
|
||||||
text: text.into(),
|
text: text.into(),
|
||||||
style: Style::default(),
|
style: Style::default(),
|
||||||
children: children.into(),
|
children: children.into(),
|
||||||
@@ -109,7 +109,7 @@ impl<'a> TreeItem<'a> {
|
|||||||
self.text.height()
|
self.text.height()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn style(mut self, style: Style) -> TreeItem<'a> {
|
pub fn style(mut self, style: Style) -> Self {
|
||||||
self.style = style;
|
self.style = style;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@@ -133,11 +133,11 @@ pub struct Tree<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Tree<'a> {
|
impl<'a> Tree<'a> {
|
||||||
pub fn new<T>(items: T) -> Tree<'a>
|
pub fn new<T>(items: T) -> Self
|
||||||
where
|
where
|
||||||
T: Into<Vec<TreeItem<'a>>>,
|
T: Into<Vec<TreeItem<'a>>>,
|
||||||
{
|
{
|
||||||
Tree {
|
Self {
|
||||||
block: None,
|
block: None,
|
||||||
style: Style::default(),
|
style: Style::default(),
|
||||||
items: items.into(),
|
items: items.into(),
|
||||||
@@ -147,27 +147,27 @@ impl<'a> Tree<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn block(mut self, block: Block<'a>) -> Tree<'a> {
|
pub fn block(mut self, block: Block<'a>) -> Self {
|
||||||
self.block = Some(block);
|
self.block = Some(block);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn style(mut self, style: Style) -> Tree<'a> {
|
pub fn style(mut self, style: Style) -> Self {
|
||||||
self.style = style;
|
self.style = style;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn highlight_symbol(mut self, highlight_symbol: &'a str) -> Tree<'a> {
|
pub fn highlight_symbol(mut self, highlight_symbol: &'a str) -> Self {
|
||||||
self.highlight_symbol = Some(highlight_symbol);
|
self.highlight_symbol = Some(highlight_symbol);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn highlight_style(mut self, style: Style) -> Tree<'a> {
|
pub fn highlight_style(mut self, style: Style) -> Self {
|
||||||
self.highlight_style = style;
|
self.highlight_style = style;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_corner(mut self, corner: Corner) -> Tree<'a> {
|
pub fn start_corner(mut self, corner: Corner) -> Self {
|
||||||
self.start_corner = corner;
|
self.start_corner = corner;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user