diff options
Diffstat (limited to 'examples/rust')
-rw-r--r-- | examples/rust/fibonacci/BUILD | 36 | ||||
-rw-r--r-- | examples/rust/fibonacci/benches/fibonacci_bench.rs | 25 | ||||
-rw-r--r-- | examples/rust/fibonacci/src/lib.rs | 48 | ||||
-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 | ||||
-rw-r--r-- | examples/rust/hello_world/BUILD | 19 | ||||
-rw-r--r-- | examples/rust/hello_world/src/main.rs | 22 |
9 files changed, 0 insertions, 299 deletions
diff --git a/examples/rust/fibonacci/BUILD b/examples/rust/fibonacci/BUILD deleted file mode 100644 index 74f7914217..0000000000 --- a/examples/rust/fibonacci/BUILD +++ /dev/null @@ -1,36 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load( - "//tools/build_rules/rust:rust.bzl", - "rust_library", - "rust_test", - "rust_bench_test", - "rust_doc", - "rust_doc_test", -) - -rust_library( - name = "fibonacci", - srcs = ["src/lib.rs"], -) - -rust_test( - name = "fibonacci_test", - deps = [":fibonacci"], -) - -rust_bench_test( - name = "fibonacci_bench", - srcs = ["benches/fibonacci_bench.rs"], - deps = [":fibonacci"], -) - -rust_doc( - name = "fibonacci_doc", - dep = ":fibonacci", -) - -rust_doc_test( - name = "fibonacci_doc_test", - dep = ":fibonacci", -) diff --git a/examples/rust/fibonacci/benches/fibonacci_bench.rs b/examples/rust/fibonacci/benches/fibonacci_bench.rs deleted file mode 100644 index 80aa1a84ce..0000000000 --- a/examples/rust/fibonacci/benches/fibonacci_bench.rs +++ /dev/null @@ -1,25 +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. - -#![feature(test)] - -extern crate test; -extern crate fibonacci; - -use test::Bencher; - -#[bench] -fn bench_fibonacci(b: &mut Bencher) { - b.iter(|| fibonacci::fibonacci(40)); -} diff --git a/examples/rust/fibonacci/src/lib.rs b/examples/rust/fibonacci/src/lib.rs deleted file mode 100644 index d8ae6e3fca..0000000000 --- a/examples/rust/fibonacci/src/lib.rs +++ /dev/null @@ -1,48 +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. - -/// Returns the nth Fibonacci number. -/// -/// # Examples -/// -/// ``` -/// fibonacci::fibonacci(5) -/// ``` -pub fn fibonacci(n: u64) -> u64 { - if n < 2 { - return n; - } - let mut n1: u64 = 0; - let mut n2: u64 = 1; - for _ in 1..n { - let sum = n1 + n2; - n1 = n2; - n2 = sum; - } - n2 -} - -#[cfg(test)] -mod test { - use super::fibonacci; - - #[test] - fn test_fibonacci() { - let numbers : Vec<u64> = - vec![0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144]; - for (i, number) in numbers.iter().enumerate() { - assert_eq!(*number, fibonacci(i as u64)); - } - } -} 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")); -} diff --git a/examples/rust/hello_world/BUILD b/examples/rust/hello_world/BUILD deleted file mode 100644 index e78362915c..0000000000 --- a/examples/rust/hello_world/BUILD +++ /dev/null @@ -1,19 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -load("//tools/build_rules/rust:rust.bzl", "rust_binary", "rust_doc", "rust_doc_test") - -rust_binary( - name = "hello_world", - srcs = ["src/main.rs"], - deps = ["//examples/rust/hello_lib"], -) - -rust_doc( - name = "hello_world_doc", - dep = ":hello_world", -) - -rust_doc_test( - name = "hello_world_doc_test", - dep = ":hello_world", -) diff --git a/examples/rust/hello_world/src/main.rs b/examples/rust/hello_world/src/main.rs deleted file mode 100644 index 03cf43fcfe..0000000000 --- a/examples/rust/hello_world/src/main.rs +++ /dev/null @@ -1,22 +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; - -fn main() { - let hello = greeter::Greeter::new("Hello"); - hello.greet("world"); -} |