aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/utils.rs
diff options
context:
space:
mode:
authorAdolfo OchagavĂ­a <[email protected]>2018-11-07 10:58:34 +0000
committerAdolfo OchagavĂ­a <[email protected]>2018-11-07 10:58:34 +0000
commit3b2ba59526f8e524aa3c1526dda2828a93653ed2 (patch)
tree3ef9368b78dfb558c8b015d0914412d49c479e60 /crates/ra_syntax/src/utils.rs
parente37ba706ccc435346c35042c2b6c4b483494268b (diff)
Use ArrayString instead of hand rolled data structure
Diffstat (limited to 'crates/ra_syntax/src/utils.rs')
-rw-r--r--crates/ra_syntax/src/utils.rs36
1 files changed, 0 insertions, 36 deletions
diff --git a/crates/ra_syntax/src/utils.rs b/crates/ra_syntax/src/utils.rs
index 5bef4a639..cad9544be 100644
--- a/crates/ra_syntax/src/utils.rs
+++ b/crates/ra_syntax/src/utils.rs
@@ -1,6 +1,5 @@
1use crate::{File, SyntaxKind, SyntaxNodeRef, WalkEvent}; 1use crate::{File, SyntaxKind, SyntaxNodeRef, WalkEvent};
2use std::fmt::Write; 2use std::fmt::Write;
3use std::ops::Deref;
4use std::str; 3use std::str;
5 4
6/// Parse a file and create a string representation of the resulting parse tree. 5/// Parse a file and create a string representation of the resulting parse tree.
@@ -80,38 +79,3 @@ pub(crate) fn validate_block_structure(root: SyntaxNodeRef) {
80 } 79 }
81 } 80 }
82} 81}
83
84#[derive(Debug)]
85pub struct MutAsciiString<'a> {
86 buf: &'a mut [u8],
87 len: usize,
88}
89
90impl<'a> MutAsciiString<'a> {
91 pub fn new(buf: &'a mut [u8]) -> MutAsciiString<'a> {
92 MutAsciiString { buf, len: 0 }
93 }
94
95 pub fn as_str(&self) -> &str {
96 str::from_utf8(&self.buf[..self.len]).unwrap()
97 }
98
99 pub fn len(&self) -> usize {
100 self.len
101 }
102
103 pub fn push(&mut self, c: char) {
104 assert!(self.len() < self.buf.len());
105 assert!(c.is_ascii());
106
107 self.buf[self.len] = c as u8;
108 self.len += 1;
109 }
110}
111
112impl<'a> Deref for MutAsciiString<'a> {
113 type Target = str;
114 fn deref(&self) -> &str {
115 self.as_str()
116 }
117}