File tree 4 files changed +40
-0
lines changed
4 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -168,6 +168,16 @@ impl KdlDocument {
168
168
self . trailing = Some ( trailing. into ( ) ) ;
169
169
}
170
170
171
+ /// Length of this document when rendered as a string.
172
+ pub fn len ( & self ) -> usize {
173
+ format ! ( "{}" , self ) . len ( )
174
+ }
175
+
176
+ /// Returns true if this document is completely empty (including whitespace)
177
+ pub fn is_empty ( & self ) -> bool {
178
+ self . len ( ) == 0
179
+ }
180
+
171
181
/// Clears leading and trailing text (whitespace, comments). `KdlNode`s in
172
182
/// this document will be unaffected.
173
183
pub fn clear_fmt ( & mut self ) {
Original file line number Diff line number Diff line change @@ -98,6 +98,16 @@ impl KdlEntry {
98
98
self . value_repr = Some ( repr. into ( ) ) ;
99
99
}
100
100
101
+ /// Length of this entry when rendered as a string.
102
+ pub fn len ( & self ) -> usize {
103
+ format ! ( "{}" , self ) . len ( )
104
+ }
105
+
106
+ /// Returns true if this entry is completely empty (including whitespace).
107
+ pub fn is_empty ( & self ) -> bool {
108
+ self . len ( ) == 0
109
+ }
110
+
101
111
/// Auto-formats this entry.
102
112
pub fn fmt ( & mut self ) {
103
113
self . leading = None ;
Original file line number Diff line number Diff line change @@ -31,6 +31,16 @@ impl KdlIdentifier {
31
31
self . repr = Some ( repr. into ( ) ) ;
32
32
}
33
33
34
+ /// Length of this identifier when rendered as a string.
35
+ pub fn len ( & self ) -> usize {
36
+ format ! ( "{}" , self ) . len ( )
37
+ }
38
+
39
+ /// Returns true if this identifier is completely empty.
40
+ pub fn is_empty ( & self ) -> bool {
41
+ self . len ( ) == 0
42
+ }
43
+
34
44
/// Resets this identifier to its default representation. It will attempt
35
45
/// to make it an unquoted identifier, and fall back to a string
36
46
/// representation if that would be invalid.
Original file line number Diff line number Diff line change @@ -106,6 +106,16 @@ impl KdlNode {
106
106
self . trailing = Some ( trailing. into ( ) ) ;
107
107
}
108
108
109
+ /// Length of this node when rendered as a string.
110
+ pub fn len ( & self ) -> usize {
111
+ format ! ( "{}" , self ) . len ( )
112
+ }
113
+
114
+ /// Returns true if this node is completely empty (including whitespace).
115
+ pub fn is_empty ( & self ) -> bool {
116
+ self . len ( ) == 0
117
+ }
118
+
109
119
/// Clears leading and trailing text (whitespace, comments), as well as
110
120
/// the space before the children block, if any. Individual entries and
111
121
/// their formatting will be preserved.
You can’t perform that action at this time.
0 commit comments