MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / push_str

Method push_str

crates/wit-bindgen/src/source.rs:12–39  ·  view source on GitHub ↗
(&mut self, src: &str)

Source from the content-addressed store, hash-verified

10
11impl Source {
12 pub fn push_str(&mut self, src: &str) {
13 let lines = src.lines().collect::<Vec<_>>();
14 for (i, line) in lines.iter().enumerate() {
15 let trimmed = line.trim();
16 if trimmed.starts_with('}') && self.s.ends_with(" ") {
17 self.s.pop();
18 self.s.pop();
19 }
20 self.s.push_str(if lines.len() == 1 {
21 line
22 } else {
23 line.trim_start()
24 });
25 if trimmed.ends_with('{') {
26 self.indent += 1;
27 }
28 if trimmed.starts_with('}') {
29 // Note that a `saturating_sub` is used here to prevent a panic
30 // here in the case of invalid code being generated in debug
31 // mode. It's typically easier to debug those issues through
32 // looking at the source code rather than getting a panic.
33 self.indent = self.indent.saturating_sub(1);
34 }
35 if i != lines.len() - 1 || src.ends_with('\n') {
36 self.newline();
37 }
38 }
39 }
40
41 pub fn indent(&mut self, amt: usize) {
42 self.indent += amt;

Callers 15

child_processFunction · 0.45
stub_itemMethod · 0.45
run_testFunction · 0.45
overrun_with_big_moduleFunction · 0.45
print_tyMethod · 0.45
print_optional_tyMethod · 0.45
tyidMethod · 0.45
print_listMethod · 0.45
print_streamMethod · 0.45
streamMethod · 0.45

Calls 5

saturating_subMethod · 0.80
newlineMethod · 0.80
iterMethod · 0.45
popMethod · 0.45
lenMethod · 0.45

Tested by 7

child_processFunction · 0.36
run_testFunction · 0.36
overrun_with_big_moduleFunction · 0.36
simple_appendFunction · 0.36
newline_remapFunction · 0.36
if_elseFunction · 0.36
trim_wsFunction · 0.36