Skip to content

Commit e40474e

Browse files
authored
Merge pull request #2 from trueaywee/main
Small cleanup
2 parents 421f101 + 19d893a commit e40474e

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

step03_mermaid/code/src/main.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,14 @@ mod mermaid {
2222
}
2323
pub fn new_participant<S: AsRef<str>>(&self, s: S) -> Participant {
2424
let mut data = self.instance.borrow_mut();
25-
let curr_i = {
26-
let i: &mut i32 = &mut data.i;
27-
*i = *i + 1;
28-
*i
29-
};
30-
Canvas::append_into(
31-
data,
32-
&format!(" create participant I{} as {}\n I0-->>I{}: create\n", curr_i, s.as_ref(), curr_i),
33-
);
34-
Participant { canvas: self, i: curr_i, _name: String::from(s.as_ref()) }
35-
}
36-
fn append_into<S: AsRef<str>>(mut data: std::cell::RefMut<Data>, s: S) {
37-
data.contents.push_str(s.as_ref());
25+
data.i += 1;
26+
let i = data.i; // or can just use data.i later on, doesn't matter
27+
drop(data);
28+
self.append(&format!(" create participant I{} as {}\n I0-->>I{}: create\n", i, s.as_ref(), i));
29+
Participant { canvas: self, i, _name: String::from(s.as_ref()) }
3830
}
3931
fn append<S: AsRef<str>>(&self, s: S) {
40-
Canvas::append_into(self.instance.borrow_mut(), s.as_ref());
32+
self.instance.borrow_mut().contents.push_str(s.as_ref());
4133
}
4234
pub fn output<F>(&self, f: F)
4335
where
@@ -46,12 +38,12 @@ mod mermaid {
4638
f(&self.instance.borrow().contents)
4739
}
4840
}
49-
impl<'a> Participant<'a> {
41+
impl Participant<'_> {
5042
pub fn add_arrow_to(&self, rhs: &Participant, text: &str) {
5143
self.canvas.append(format!(" I{}->>I{}: {}\n", self.i, rhs.i, text));
5244
}
5345
}
54-
impl<'a> Drop for Participant<'a> {
46+
impl Drop for Participant<'_> {
5547
fn drop(&mut self) {
5648
self.canvas.append(format!(" destroy I{}\n I{}-->>I0: destroy\n", self.i, self.i));
5749
}

0 commit comments

Comments
 (0)