dprint_core/formatting/
condition_resolvers.rs1use std::rc::Rc;
2
3use super::print_items::*;
4
5thread_local! {
6 static TRUE: ConditionResolver = Rc::new(|_| {
7 Some(true)
8 });
9
10 static FALSE: ConditionResolver = Rc::new(|_| {
11 Some(false)
12 });
13
14 static IS_START_OF_LINE_RESOLVER: ConditionResolver = Rc::new(|context| {
15 Some(context.writer_info.is_start_of_line())
16 });
17
18 static IS_NOT_START_OF_LINE_RESOLVER: ConditionResolver = Rc::new(|context| {
19 Some(!context.writer_info.is_start_of_line())
20 });
21
22 static IS_START_OF_LINE_INDENTED: ConditionResolver = Rc::new(|context| {
23 Some(context.writer_info.is_start_of_line_indented())
24 });
25
26 static IS_START_OF_LINE_OR_IS_START_OF_LINE_INDENTED: ConditionResolver = Rc::new(|context| {
27 Some(context.writer_info.is_start_of_line_indented() || context.writer_info.is_start_of_line())
28 });
29
30 static IS_FORCING_NO_NEWLINES: ConditionResolver = Rc::new(|context| {
31 Some(context.is_forcing_no_newlines())
32 });
33}
34
35pub fn true_resolver() -> ConditionResolver {
36 TRUE.with(|r| r.clone())
37}
38
39pub fn false_resolver() -> ConditionResolver {
40 FALSE.with(|r| r.clone())
41}
42
43pub fn is_start_of_line() -> ConditionResolver {
44 IS_START_OF_LINE_RESOLVER.with(|r| r.clone())
45}
46
47pub fn is_not_start_of_line() -> ConditionResolver {
48 IS_NOT_START_OF_LINE_RESOLVER.with(|r| r.clone())
49}
50
51pub fn is_start_of_line_indented() -> ConditionResolver {
52 IS_START_OF_LINE_INDENTED.with(|r| r.clone())
53}
54
55pub fn is_start_of_line_or_is_start_of_line_indented() -> ConditionResolver {
56 IS_START_OF_LINE_OR_IS_START_OF_LINE_INDENTED.with(|r| r.clone())
57}
58
59pub fn is_forcing_no_newlines() -> ConditionResolver {
60 IS_FORCING_NO_NEWLINES.with(|r| r.clone())
61}