2020-02-07 14:57:38 +00:00
|
|
|
//! Assorted functions shared by several assists.
|
2020-02-28 20:53:20 +00:00
|
|
|
pub(crate) mod insert_use;
|
2020-10-12 16:11:36 +00:00
|
|
|
pub(crate) mod import_assets;
|
2020-02-07 14:57:38 +00:00
|
|
|
|
2020-10-24 07:47:23 +00:00
|
|
|
use std::ops;
|
2020-04-29 09:57:06 +00:00
|
|
|
|
2020-11-05 22:34:50 +00:00
|
|
|
use hir::{Crate, Enum, HasSource, Module, ScopeDef, Semantics, Trait};
|
2020-08-13 14:39:16 +00:00
|
|
|
use ide_db::RootDatabase;
|
2020-08-13 09:41:20 +00:00
|
|
|
use itertools::Itertools;
|
2020-08-12 16:26:51 +00:00
|
|
|
use syntax::{
|
2020-11-05 22:34:50 +00:00
|
|
|
ast::edit::AstNodeEdit,
|
|
|
|
ast::NameOwner,
|
|
|
|
ast::{self, edit, make, ArgListOwner},
|
2020-08-19 16:44:33 +00:00
|
|
|
AstNode, Direction,
|
2020-06-28 22:18:50 +00:00
|
|
|
SyntaxKind::*,
|
2020-08-25 08:57:51 +00:00
|
|
|
SyntaxNode, TextSize, T,
|
2020-02-07 14:57:38 +00:00
|
|
|
};
|
2020-02-09 18:24:34 +00:00
|
|
|
|
2020-11-05 22:34:50 +00:00
|
|
|
use crate::{
|
|
|
|
assist_config::SnippetCap,
|
|
|
|
ast_transform::{self, AstTransform, QualifyPaths, SubstituteTypeParams},
|
|
|
|
};
|
2020-05-19 21:12:01 +00:00
|
|
|
|
2020-09-12 09:55:01 +00:00
|
|
|
pub use insert_use::MergeBehaviour;
|
|
|
|
pub(crate) use insert_use::{insert_use, ImportScope};
|
2020-02-28 20:53:20 +00:00
|
|
|
|
2020-10-06 14:19:18 +00:00
|
|
|
pub fn mod_path_to_ast(path: &hir::ModPath) -> ast::Path {
|
|
|
|
let mut segments = Vec::new();
|
|
|
|
let mut is_abs = false;
|
|
|
|
match path.kind {
|
|
|
|
hir::PathKind::Plain => {}
|
|
|
|
hir::PathKind::Super(0) => segments.push(make::path_segment_self()),
|
|
|
|
hir::PathKind::Super(n) => segments.extend((0..n).map(|_| make::path_segment_super())),
|
|
|
|
hir::PathKind::DollarCrate(_) | hir::PathKind::Crate => {
|
|
|
|
segments.push(make::path_segment_crate())
|
|
|
|
}
|
|
|
|
hir::PathKind::Abs => is_abs = true,
|
|
|
|
}
|
|
|
|
|
|
|
|
segments.extend(
|
|
|
|
path.segments
|
|
|
|
.iter()
|
|
|
|
.map(|segment| make::path_segment(make::name_ref(&segment.to_string()))),
|
|
|
|
);
|
|
|
|
make::path_from_segments(segments, is_abs)
|
|
|
|
}
|
|
|
|
|
2020-08-13 09:41:20 +00:00
|
|
|
pub(crate) fn unwrap_trivial_block(block: ast::BlockExpr) -> ast::Expr {
|
|
|
|
extract_trivial_expression(&block)
|
|
|
|
.filter(|expr| !expr.syntax().text().contains_char('\n'))
|
|
|
|
.unwrap_or_else(|| block.into())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn extract_trivial_expression(block: &ast::BlockExpr) -> Option<ast::Expr> {
|
|
|
|
let has_anything_else = |thing: &SyntaxNode| -> bool {
|
|
|
|
let mut non_trivial_children =
|
|
|
|
block.syntax().children_with_tokens().filter(|it| match it.kind() {
|
|
|
|
WHITESPACE | T!['{'] | T!['}'] => false,
|
|
|
|
_ => it.as_node() != Some(thing),
|
|
|
|
});
|
|
|
|
non_trivial_children.next().is_some()
|
|
|
|
};
|
|
|
|
|
|
|
|
if let Some(expr) = block.expr() {
|
|
|
|
if has_anything_else(expr.syntax()) {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
return Some(expr);
|
|
|
|
}
|
|
|
|
// Unwrap `{ continue; }`
|
|
|
|
let (stmt,) = block.statements().next_tuple()?;
|
|
|
|
if let ast::Stmt::ExprStmt(expr_stmt) = stmt {
|
|
|
|
if has_anything_else(expr_stmt.syntax()) {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
let expr = expr_stmt.expr()?;
|
|
|
|
match expr.syntax().kind() {
|
|
|
|
CONTINUE_EXPR | BREAK_EXPR | RETURN_EXPR => return Some(expr),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2020-11-05 22:34:50 +00:00
|
|
|
#[derive(Copy, Clone, PartialEq)]
|
|
|
|
pub enum DefaultMethods {
|
|
|
|
Only,
|
|
|
|
No,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn filter_assoc_items(
|
|
|
|
db: &RootDatabase,
|
|
|
|
items: &[hir::AssocItem],
|
|
|
|
default_methods: DefaultMethods,
|
|
|
|
) -> Vec<ast::AssocItem> {
|
|
|
|
fn has_def_name(item: &ast::AssocItem) -> bool {
|
|
|
|
match item {
|
|
|
|
ast::AssocItem::Fn(def) => def.name(),
|
|
|
|
ast::AssocItem::TypeAlias(def) => def.name(),
|
|
|
|
ast::AssocItem::Const(def) => def.name(),
|
|
|
|
ast::AssocItem::MacroCall(_) => None,
|
|
|
|
}
|
|
|
|
.is_some()
|
|
|
|
};
|
|
|
|
|
|
|
|
items
|
|
|
|
.iter()
|
|
|
|
.map(|i| match i {
|
|
|
|
hir::AssocItem::Function(i) => ast::AssocItem::Fn(i.source(db).value),
|
|
|
|
hir::AssocItem::TypeAlias(i) => ast::AssocItem::TypeAlias(i.source(db).value),
|
|
|
|
hir::AssocItem::Const(i) => ast::AssocItem::Const(i.source(db).value),
|
|
|
|
})
|
|
|
|
.filter(has_def_name)
|
|
|
|
.filter(|it| match it {
|
|
|
|
ast::AssocItem::Fn(def) => matches!(
|
|
|
|
(default_methods, def.body()),
|
|
|
|
(DefaultMethods::Only, Some(_)) | (DefaultMethods::No, None)
|
|
|
|
),
|
|
|
|
_ => default_methods == DefaultMethods::No,
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_trait_assoc_items_to_impl(
|
|
|
|
sema: &hir::Semantics<ide_db::RootDatabase>,
|
|
|
|
items: Vec<ast::AssocItem>,
|
|
|
|
trait_: hir::Trait,
|
|
|
|
impl_def: ast::Impl,
|
|
|
|
target_scope: hir::SemanticsScope,
|
|
|
|
) -> (ast::Impl, ast::AssocItem) {
|
|
|
|
let impl_item_list = impl_def.assoc_item_list().unwrap_or_else(make::assoc_item_list);
|
|
|
|
|
|
|
|
let n_existing_items = impl_item_list.assoc_items().count();
|
|
|
|
let source_scope = sema.scope_for_def(trait_);
|
|
|
|
let ast_transform = QualifyPaths::new(&target_scope, &source_scope)
|
|
|
|
.or(SubstituteTypeParams::for_trait_impl(&source_scope, trait_, impl_def.clone()));
|
|
|
|
|
|
|
|
let items = items
|
|
|
|
.into_iter()
|
|
|
|
.map(|it| ast_transform::apply(&*ast_transform, it))
|
|
|
|
.map(|it| match it {
|
|
|
|
ast::AssocItem::Fn(def) => ast::AssocItem::Fn(add_body(def)),
|
|
|
|
ast::AssocItem::TypeAlias(def) => ast::AssocItem::TypeAlias(def.remove_bounds()),
|
|
|
|
_ => it,
|
|
|
|
})
|
|
|
|
.map(|it| edit::remove_attrs_and_docs(&it));
|
|
|
|
|
|
|
|
let new_impl_item_list = impl_item_list.append_items(items);
|
|
|
|
let new_impl_def = impl_def.with_assoc_item_list(new_impl_item_list);
|
|
|
|
let first_new_item =
|
|
|
|
new_impl_def.assoc_item_list().unwrap().assoc_items().nth(n_existing_items).unwrap();
|
|
|
|
return (new_impl_def, first_new_item);
|
|
|
|
|
|
|
|
fn add_body(fn_def: ast::Fn) -> ast::Fn {
|
|
|
|
match fn_def.body() {
|
|
|
|
Some(_) => fn_def,
|
|
|
|
None => {
|
|
|
|
let body =
|
|
|
|
make::block_expr(None, Some(make::expr_todo())).indent(edit::IndentLevel(1));
|
|
|
|
fn_def.with_body(body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 23:53:21 +00:00
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
|
|
pub(crate) enum Cursor<'a> {
|
|
|
|
Replace(&'a SyntaxNode),
|
|
|
|
Before(&'a SyntaxNode),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Cursor<'a> {
|
|
|
|
fn node(self) -> &'a SyntaxNode {
|
|
|
|
match self {
|
|
|
|
Cursor::Replace(node) | Cursor::Before(node) => node,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn render_snippet(_cap: SnippetCap, node: &SyntaxNode, cursor: Cursor) -> String {
|
|
|
|
assert!(cursor.node().ancestors().any(|it| it == *node));
|
|
|
|
let range = cursor.node().text_range() - node.text_range().start();
|
2020-05-19 20:25:07 +00:00
|
|
|
let range: ops::Range<usize> = range.into();
|
|
|
|
|
2020-05-19 23:53:21 +00:00
|
|
|
let mut placeholder = cursor.node().to_string();
|
2020-05-19 20:25:07 +00:00
|
|
|
escape(&mut placeholder);
|
2020-05-19 23:53:21 +00:00
|
|
|
let tab_stop = match cursor {
|
|
|
|
Cursor::Replace(placeholder) => format!("${{0:{}}}", placeholder),
|
|
|
|
Cursor::Before(placeholder) => format!("$0{}", placeholder),
|
|
|
|
};
|
2020-05-19 20:25:07 +00:00
|
|
|
|
|
|
|
let mut buf = node.to_string();
|
|
|
|
buf.replace_range(range, &tab_stop);
|
|
|
|
return buf;
|
|
|
|
|
|
|
|
fn escape(buf: &mut String) {
|
|
|
|
stdx::replace(buf, '{', r"\{");
|
|
|
|
stdx::replace(buf, '}', r"\}");
|
|
|
|
stdx::replace(buf, '$', r"\$");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-28 22:18:50 +00:00
|
|
|
pub(crate) fn vis_offset(node: &SyntaxNode) -> TextSize {
|
|
|
|
node.children_with_tokens()
|
|
|
|
.find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
|
|
|
|
.map(|it| it.text_range().start())
|
|
|
|
.unwrap_or_else(|| node.text_range().start())
|
|
|
|
}
|
|
|
|
|
2020-02-07 14:57:38 +00:00
|
|
|
pub(crate) fn invert_boolean_expression(expr: ast::Expr) -> ast::Expr {
|
|
|
|
if let Some(expr) = invert_special_case(&expr) {
|
|
|
|
return expr;
|
|
|
|
}
|
|
|
|
make::expr_prefix(T![!], expr)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn invert_special_case(expr: &ast::Expr) -> Option<ast::Expr> {
|
|
|
|
match expr {
|
|
|
|
ast::Expr::BinExpr(bin) => match bin.op_kind()? {
|
|
|
|
ast::BinOp::NegatedEqualityTest => bin.replace_op(T![==]).map(|it| it.into()),
|
|
|
|
ast::BinOp::EqualityTest => bin.replace_op(T![!=]).map(|it| it.into()),
|
|
|
|
_ => None,
|
|
|
|
},
|
2020-08-23 20:30:07 +00:00
|
|
|
ast::Expr::MethodCallExpr(mce) => {
|
2020-08-25 08:57:51 +00:00
|
|
|
let receiver = mce.receiver()?;
|
|
|
|
let method = mce.name_ref()?;
|
|
|
|
let arg_list = mce.arg_list()?;
|
|
|
|
|
|
|
|
let method = match method.text().as_str() {
|
|
|
|
"is_some" => "is_none",
|
|
|
|
"is_none" => "is_some",
|
|
|
|
"is_ok" => "is_err",
|
|
|
|
"is_err" => "is_ok",
|
|
|
|
_ => return None,
|
|
|
|
};
|
|
|
|
Some(make::expr_method_call(receiver, method, arg_list))
|
2020-08-23 20:30:07 +00:00
|
|
|
}
|
2020-02-07 14:57:38 +00:00
|
|
|
ast::Expr::PrefixExpr(pe) if pe.op_kind()? == ast::PrefixOp::Not => pe.expr(),
|
|
|
|
// FIXME:
|
|
|
|
// ast::Expr::Literal(true | false )
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2020-04-29 08:38:18 +00:00
|
|
|
|
2020-04-29 12:49:54 +00:00
|
|
|
/// Helps with finding well-know things inside the standard library. This is
|
|
|
|
/// somewhat similar to the known paths infra inside hir, but it different; We
|
|
|
|
/// want to make sure that IDE specific paths don't become interesting inside
|
|
|
|
/// the compiler itself as well.
|
2020-10-20 15:38:21 +00:00
|
|
|
pub struct FamousDefs<'a, 'b>(pub &'a Semantics<'b, RootDatabase>, pub Option<Crate>);
|
2020-04-29 12:49:54 +00:00
|
|
|
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
impl FamousDefs<'_, '_> {
|
2020-10-06 19:05:57 +00:00
|
|
|
pub const FIXTURE: &'static str = r#"//- /libcore.rs crate:core
|
2020-05-20 08:51:48 +00:00
|
|
|
pub mod convert {
|
2020-04-29 12:49:54 +00:00
|
|
|
pub trait From<T> {
|
2020-10-07 09:30:42 +00:00
|
|
|
fn from(t: T) -> Self;
|
2020-04-29 12:49:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-13 16:17:16 +00:00
|
|
|
pub mod default {
|
2020-11-13 22:20:26 +00:00
|
|
|
pub trait Default {
|
2020-11-13 16:17:16 +00:00
|
|
|
fn default() -> Self;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-06 19:05:57 +00:00
|
|
|
pub mod iter {
|
2020-10-07 08:14:42 +00:00
|
|
|
pub use self::traits::{collect::IntoIterator, iterator::Iterator};
|
|
|
|
mod traits {
|
2020-10-07 09:30:42 +00:00
|
|
|
pub(crate) mod iterator {
|
2020-10-07 08:14:42 +00:00
|
|
|
use crate::option::Option;
|
|
|
|
pub trait Iterator {
|
|
|
|
type Item;
|
|
|
|
fn next(&mut self) -> Option<Self::Item>;
|
2020-10-07 09:30:42 +00:00
|
|
|
fn by_ref(&mut self) -> &mut Self {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
fn take(self, n: usize) -> crate::iter::Take<Self> {
|
|
|
|
crate::iter::Take { inner: self }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<I: Iterator> Iterator for &mut I {
|
|
|
|
type Item = I::Item;
|
|
|
|
fn next(&mut self) -> Option<I::Item> {
|
|
|
|
(**self).next()
|
|
|
|
}
|
2020-10-07 08:14:42 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-07 10:13:32 +00:00
|
|
|
pub(crate) mod collect {
|
2020-10-07 08:14:42 +00:00
|
|
|
pub trait IntoIterator {
|
|
|
|
type Item;
|
|
|
|
}
|
2020-10-06 19:05:57 +00:00
|
|
|
}
|
2020-10-07 08:14:42 +00:00
|
|
|
}
|
2020-10-06 19:05:57 +00:00
|
|
|
|
|
|
|
pub use self::sources::*;
|
2020-10-07 09:30:42 +00:00
|
|
|
pub(crate) mod sources {
|
2020-10-06 19:05:57 +00:00
|
|
|
use super::Iterator;
|
2020-10-07 09:30:42 +00:00
|
|
|
use crate::option::Option::{self, *};
|
2020-10-06 19:05:57 +00:00
|
|
|
pub struct Repeat<A> {
|
|
|
|
element: A,
|
|
|
|
}
|
|
|
|
|
2020-10-07 09:30:42 +00:00
|
|
|
pub fn repeat<T>(elt: T) -> Repeat<T> {
|
2020-10-06 19:05:57 +00:00
|
|
|
Repeat { element: elt }
|
|
|
|
}
|
|
|
|
|
2020-10-07 09:30:42 +00:00
|
|
|
impl<A> Iterator for Repeat<A> {
|
2020-10-06 19:05:57 +00:00
|
|
|
type Item = A;
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<A> {
|
2020-10-07 09:30:42 +00:00
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub use self::adapters::*;
|
|
|
|
pub(crate) mod adapters {
|
|
|
|
use super::Iterator;
|
|
|
|
use crate::option::Option::{self, *};
|
|
|
|
pub struct Take<I> { pub(crate) inner: I }
|
|
|
|
impl<I> Iterator for Take<I> where I: Iterator {
|
|
|
|
type Item = <I as Iterator>::Item;
|
|
|
|
fn next(&mut self) -> Option<<I as Iterator>::Item> {
|
|
|
|
None
|
2020-10-06 19:05:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-20 08:51:48 +00:00
|
|
|
pub mod option {
|
|
|
|
pub enum Option<T> { None, Some(T)}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub mod prelude {
|
2020-11-13 16:17:16 +00:00
|
|
|
pub use crate::{convert::From, iter::{IntoIterator, Iterator}, option::Option::{self, *}, default::Default};
|
2020-05-20 08:51:48 +00:00
|
|
|
}
|
2020-04-29 12:49:54 +00:00
|
|
|
#[prelude_import]
|
|
|
|
pub use prelude::*;
|
|
|
|
"#;
|
|
|
|
|
2020-10-20 15:38:21 +00:00
|
|
|
pub fn core(&self) -> Option<Crate> {
|
|
|
|
self.find_crate("core")
|
|
|
|
}
|
|
|
|
|
2020-04-29 12:49:54 +00:00
|
|
|
pub(crate) fn core_convert_From(&self) -> Option<Trait> {
|
|
|
|
self.find_trait("core:convert:From")
|
|
|
|
}
|
|
|
|
|
2020-05-20 08:51:48 +00:00
|
|
|
pub(crate) fn core_option_Option(&self) -> Option<Enum> {
|
|
|
|
self.find_enum("core:option:Option")
|
|
|
|
}
|
|
|
|
|
2020-11-13 16:17:16 +00:00
|
|
|
pub fn core_default_Default(&self) -> Option<Trait> {
|
|
|
|
self.find_trait("core:default:Default")
|
|
|
|
}
|
|
|
|
|
2020-10-06 19:05:57 +00:00
|
|
|
pub fn core_iter_Iterator(&self) -> Option<Trait> {
|
|
|
|
self.find_trait("core:iter:traits:iterator:Iterator")
|
|
|
|
}
|
|
|
|
|
2020-10-07 11:14:12 +00:00
|
|
|
pub fn core_iter(&self) -> Option<Module> {
|
|
|
|
self.find_module("core:iter")
|
|
|
|
}
|
|
|
|
|
2020-04-29 12:49:54 +00:00
|
|
|
fn find_trait(&self, path: &str) -> Option<Trait> {
|
2020-05-20 08:51:48 +00:00
|
|
|
match self.find_def(path)? {
|
|
|
|
hir::ScopeDef::ModuleDef(hir::ModuleDef::Trait(it)) => Some(it),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn find_enum(&self, path: &str) -> Option<Enum> {
|
|
|
|
match self.find_def(path)? {
|
|
|
|
hir::ScopeDef::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Enum(it))) => Some(it),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-07 11:14:12 +00:00
|
|
|
fn find_module(&self, path: &str) -> Option<Module> {
|
|
|
|
match self.find_def(path)? {
|
|
|
|
hir::ScopeDef::ModuleDef(hir::ModuleDef::Module(it)) => Some(it),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-20 15:38:21 +00:00
|
|
|
fn find_crate(&self, name: &str) -> Option<Crate> {
|
|
|
|
let krate = self.1?;
|
|
|
|
let db = self.0.db;
|
|
|
|
let res =
|
|
|
|
krate.dependencies(db).into_iter().find(|dep| dep.name.to_string() == name)?.krate;
|
|
|
|
Some(res)
|
|
|
|
}
|
|
|
|
|
2020-05-20 08:51:48 +00:00
|
|
|
fn find_def(&self, path: &str) -> Option<ScopeDef> {
|
2020-04-29 12:49:54 +00:00
|
|
|
let db = self.0.db;
|
|
|
|
let mut path = path.split(':');
|
|
|
|
let trait_ = path.next_back()?;
|
|
|
|
let std_crate = path.next()?;
|
2020-10-20 15:38:21 +00:00
|
|
|
let std_crate = self.find_crate(std_crate)?;
|
2020-08-09 22:52:19 +00:00
|
|
|
let mut module = std_crate.root_module(db);
|
2020-04-29 12:49:54 +00:00
|
|
|
for segment in path {
|
|
|
|
module = module.children(db).find_map(|child| {
|
|
|
|
let name = child.name(db)?;
|
2020-10-06 19:05:57 +00:00
|
|
|
if name.to_string() == segment {
|
2020-04-29 12:49:54 +00:00
|
|
|
Some(child)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
})?;
|
|
|
|
}
|
|
|
|
let def =
|
2020-10-06 19:05:57 +00:00
|
|
|
module.scope(db, None).into_iter().find(|(name, _def)| name.to_string() == trait_)?.1;
|
2020-05-20 08:51:48 +00:00
|
|
|
Some(def)
|
2020-04-29 12:49:54 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-19 16:44:33 +00:00
|
|
|
|
|
|
|
pub(crate) fn next_prev() -> impl Iterator<Item = Direction> {
|
|
|
|
[Direction::Next, Direction::Prev].iter().copied()
|
|
|
|
}
|