Changeset View
Changeset View
Standalone View
Standalone View
tests/rust_functions/src/implementation.rs
- This file was added.
1 | #![allow(unused_imports)] | ||||
---|---|---|---|---|---|
2 | #![allow(unused_variables)] | ||||
3 | #![allow(dead_code)] | ||||
4 | use interface::*; | ||||
5 | | ||||
6 | pub struct Person { | ||||
7 | emit: PersonEmitter, | ||||
8 | user_name: String, | ||||
9 | } | ||||
10 | | ||||
11 | impl PersonTrait for Person { | ||||
12 | fn new(emit: PersonEmitter) -> Person { | ||||
13 | Person { | ||||
14 | emit: emit, | ||||
15 | user_name: String::new(), | ||||
16 | } | ||||
17 | } | ||||
18 | fn emit(&self) -> &PersonEmitter { | ||||
19 | &self.emit | ||||
20 | } | ||||
21 | fn user_name(&self) -> &str { | ||||
22 | &self.user_name | ||||
23 | } | ||||
24 | fn set_user_name(&mut self, value: String) { | ||||
25 | self.user_name = value; | ||||
26 | self.emit.user_name_changed(); | ||||
27 | } | ||||
28 | | ||||
29 | fn double_name(&mut self) { | ||||
30 | self.user_name = format!("{}{}", self.user_name, self.user_name); | ||||
31 | } | ||||
32 | | ||||
33 | fn greet(&self, name: String) -> String { | ||||
34 | format!("Hello {}, my name is {}, how is it going?", name, self.user_name) | ||||
35 | } | ||||
36 | | ||||
37 | fn vowels_in_name(&self) -> u8 { | ||||
38 | self.user_name.chars().fold(0, |count, ch| match ch { | ||||
39 | 'a'|'e'|'i'|'o'|'u' => count + 1, | ||||
40 | _ => count | ||||
41 | }) | ||||
42 | } | ||||
43 | } | ||||
44 | |