1use crate::{
2 formatter::*,
3 utils::map::byte_span::{ByteSpan, LeafSpans},
4};
5use sway_ast::ItemKind::{self, *};
6
7impl Format for ItemKind {
8 fn format(
9 &self,
10 formatted_code: &mut FormattedCode,
11 formatter: &mut Formatter,
12 ) -> Result<(), FormatterError> {
13 match self {
14 Submodule(item_mod) => item_mod.format(formatted_code, formatter),
15 Use(item_use) => item_use.format(formatted_code, formatter),
16 Struct(item_struct) => item_struct.format(formatted_code, formatter),
17 Enum(item_enum) => item_enum.format(formatted_code, formatter),
18 Fn(item_fn) => item_fn.format(formatted_code, formatter),
19 Trait(item_trait) => item_trait.format(formatted_code, formatter),
20 Impl(item_impl) => item_impl.format(formatted_code, formatter),
21 Abi(item_abi) => item_abi.format(formatted_code, formatter),
22 Const(item_const) => item_const.format(formatted_code, formatter),
23 Storage(item_storage) => item_storage.format(formatted_code, formatter),
24 Configurable(item_configurable) => item_configurable.format(formatted_code, formatter),
25 TypeAlias(item_type_alias) => item_type_alias.format(formatted_code, formatter),
26 Error(_, _) => Ok(()),
27 }
28 }
29}
30
31impl LeafSpans for ItemKind {
32 fn leaf_spans(&self) -> Vec<ByteSpan> {
33 match self {
34 Submodule(item_mod) => item_mod.leaf_spans(),
35 Struct(item_struct) => item_struct.leaf_spans(),
36 Enum(item_enum) => item_enum.leaf_spans(),
37 Fn(item_fn) => item_fn.leaf_spans(),
38 Abi(item_abi) => item_abi.leaf_spans(),
39 Const(item_const) => item_const.leaf_spans(),
40 Storage(item_storage) => item_storage.leaf_spans(),
41 Trait(item_trait) => item_trait.leaf_spans(),
42 Impl(item_impl) => item_impl.leaf_spans(),
43 Use(item_use) => item_use.leaf_spans(),
44 Configurable(item_configurable) => item_configurable.leaf_spans(),
45 TypeAlias(item_type_alias) => item_type_alias.leaf_spans(),
46 Error(spans, _) => {
47 vec![sway_types::Span::join_all(spans.iter().cloned()).into()]
48 }
49 }
50 }
51}
52
53pub trait ItemLenChars {
54 fn len_chars(&self) -> Result<usize, FormatterError>;
55}