From 4eb82ec1fe39eff42aa5b1b4246fd941183abe6a Mon Sep 17 00:00:00 2001 From: David Chen Date: Thu, 24 Sep 2015 09:24:24 +0000 Subject: 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 --- examples/rust/hello_lib/BUILD | 7 ++++++- examples/rust/hello_lib/src/greeter.rs | 31 +++++++++++++++++++++++++++++++ examples/rust/hello_world/BUILD | 7 ++++++- 3 files changed, 43 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/rust/hello_lib/BUILD b/examples/rust/hello_lib/BUILD index 64cc935b27..a075f8b168 100644 --- a/examples/rust/hello_lib/BUILD +++ b/examples/rust/hello_lib/BUILD @@ -1,6 +1,6 @@ package(default_visibility = ["//visibility:public"]) -load("/tools/build_rules/rust/rust", "rust_library", "rust_test") +load("/tools/build_rules/rust/rust", "rust_library", "rust_docs", "rust_test") rust_library( name = "hello_lib", @@ -10,6 +10,11 @@ rust_library( ], ) +rust_docs( + name = "hello_lib_docs", + dep = ":hello_lib", +) + rust_test( name = "greeting", srcs = ["tests/greeting.rs"], 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); } diff --git a/examples/rust/hello_world/BUILD b/examples/rust/hello_world/BUILD index e774dcc835..ccd87f1b93 100644 --- a/examples/rust/hello_world/BUILD +++ b/examples/rust/hello_world/BUILD @@ -1,9 +1,14 @@ package(default_visibility = ["//visibility:public"]) -load("/tools/build_rules/rust/rust", "rust_binary") +load("/tools/build_rules/rust/rust", "rust_binary", "rust_docs") rust_binary( name = "hello_world", srcs = ["src/main.rs"], deps = ["//examples/rust/hello_lib"], ) + +rust_docs( + name = "hello_world_docs", + dep = ":hello_world", +) -- cgit v1.2.3