aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/rust/hello_lib/src/greeter.rs
diff options
context:
space:
mode:
authorGravatar David Chen <dzc@google.com>2015-09-24 09:24:24 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2015-09-24 14:22:00 +0000
commit4eb82ec1fe39eff42aa5b1b4246fd941183abe6a (patch)
treedcfff8870a7ebc87e6d6cde3dabace93640b825a /examples/rust/hello_lib/src/greeter.rs
parentd6f6b7dac79d122ba81d7e2b0f53feac7b225f1d (diff)
Add rust_docs rule
Additional updates to Rust rules: * Consolidate BUILD files for Rust distribution. * Prevent rust_binary from depending directly on cc_library. * Update Rust version to 1.3.0 RELNOTES: [rust] Add rust_docs rule for generating rustdoc. -- MOS_MIGRATED_REVID=103827592
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);
}