diff options
Diffstat (limited to 'examples/rust/hello_lib')
-rw-r--r-- | examples/rust/hello_lib/BUILD | 38 | ||||
-rw-r--r-- | examples/rust/hello_lib/src/greeter.rs | 73 | ||||
-rw-r--r-- | examples/rust/hello_lib/src/lib.rs | 15 | ||||
-rw-r--r-- | examples/rust/hello_lib/tests/greeting.rs | 23 |
4 files changed, 0 insertions, 149 deletions
diff --git a/examples/rust/hello_lib/BUILD b/examples/rust/hello_lib/BUILD deleted file mode 100644 index c47368727a..0000000000 --- a/examples/rust/hello_lib/BUILD +++ /dev/null @@ -1,38 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load( - "//tools/build_rules/rust:rust.bzl", - "rust_library", - "rust_test", - "rust_doc", - "rust_doc_test", -) - -rust_library( - name = "hello_lib", - srcs = [ - "src/greeter.rs", - "src/lib.rs", - ], -) - -rust_test( - name = "hello_lib_test", - deps = [":hello_lib"], -) - -rust_test( - name = "greeting_test", - srcs = ["tests/greeting.rs"], - deps = [":hello_lib"], -) - -rust_doc( - name = "hello_lib_doc", - dep = ":hello_lib", -) - -rust_doc_test( - name = "hello_lib_doc_test", - dep = ":hello_lib", -) diff --git a/examples/rust/hello_lib/src/greeter.rs b/examples/rust/hello_lib/src/greeter.rs deleted file mode 100644 index bf332e4bd1..0000000000 --- a/examples/rust/hello_lib/src/greeter.rs +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2015 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// 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); - } -} - -#[cfg(test)] -mod test { - use super::Greeter; - - #[test] - fn test_greeting() { - let hello = Greeter::new("Hi"); - assert_eq!("Hi Rust", hello.greeting("Rust")); - } -} diff --git a/examples/rust/hello_lib/src/lib.rs b/examples/rust/hello_lib/src/lib.rs deleted file mode 100644 index 9dc608911f..0000000000 --- a/examples/rust/hello_lib/src/lib.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2015 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -pub mod greeter; diff --git a/examples/rust/hello_lib/tests/greeting.rs b/examples/rust/hello_lib/tests/greeting.rs deleted file mode 100644 index be3435681b..0000000000 --- a/examples/rust/hello_lib/tests/greeting.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2015 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -extern crate hello_lib; - -use hello_lib::greeter; - -#[test] -fn test_greeting() { - let hello = greeter::Greeter::new("Hello"); - assert_eq!("Hello world", hello.greeting("world")); -} |