aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/rust/hello_lib/src/greeter.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/rust/hello_lib/src/greeter.rs')
-rw-r--r--examples/rust/hello_lib/src/greeter.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/examples/rust/hello_lib/src/greeter.rs b/examples/rust/hello_lib/src/greeter.rs
index be59ff888d..2a4a2f1d3f 100644
--- a/examples/rust/hello_lib/src/greeter.rs
+++ b/examples/rust/hello_lib/src/greeter.rs
@@ -12,19 +12,50 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+/// Object that displays a greeting.
pub struct Greeter {
greeting: String,
}
+/// Implementation of Greeter.
impl Greeter {
+ /// Constructs a new `Greeter`.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use hello_lib::greeter;
+ ///
+ /// let greeter = Greeter::new("Hello");
+ /// ```
pub fn new(greeting: &str) -> Greeter {
Greeter { greeting: greeting.to_string(), }
}
+ /// Returns the greeting as a string.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use hello_lib::greeter;
+ ///
+ /// let greeter = Greeter::new("Hello");
+ /// let greeting = greeter.greeting("World");
+ /// ```
pub fn greeting(&self, thing: &str) -> String {
format!("{} {}", &self.greeting, thing)
}
+ /// Prints the greeting.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use hello_lib::greeter;
+ ///
+ /// let greeter = Greeter::new("Hello");
+ /// greeter.greet("World");
+ /// ```
pub fn greet(&self, thing: &str) {
println!("{} {}", &self.greeting, thing);
}