use super::*;
use crate::PrettyBuilder;
#[derive(Copy, Clone, Debug)]
pub struct KAndRBracket {
pub head_space: bool,
pub bracket_l: &'static str,
pub bracket_r: &'static str,
}
impl KAndRBracket {
pub fn curly_braces() -> Self {
Self { head_space: true, bracket_l: "{", bracket_r: "}" }
}
pub fn build<'a, I>(
&self,
items: &[I],
allocator: &'a PrettyProvider,
inline_join: PrettyTree,
block_join: PrettyTree,
) -> PrettyTree
where
I: PrettyPrint,
{
let mut output = PrettySequence::new(5);
if self.head_space {
output.push(" ");
}
output.push(self.bracket_l);
let mut inline = PrettySequence::new(3);
inline.push(" ");
inline.push(allocator.join(items, inline_join));
inline.push(" ");
let mut block = PrettySequence::new(3);
block.push(PrettyTree::Hardline);
block.push(allocator.join(items, block_join).indent(4));
block.push(PrettyTree::Hardline);
output.push(block.flat_alt(inline));
output.push(self.bracket_r);
output.into()
}
}