From 4dfc11d74ab02ac5765ae5d08fb750c91f4744b4 Mon Sep 17 00:00:00 2001 From: Hunter Kvalevog Date: Fri, 2 Oct 2026 21:53:51 -0500 Subject: rustlings: move to rust/ --- rustlings/solutions/15_traits/traits1.rs | 32 -------------------------- rustlings/solutions/15_traits/traits2.rs | 27 ---------------------- rustlings/solutions/15_traits/traits3.rs | 36 ----------------------------- rustlings/solutions/15_traits/traits4.rs | 35 ---------------------------- rustlings/solutions/15_traits/traits5.rs | 39 -------------------------------- 5 files changed, 169 deletions(-) delete mode 100644 rustlings/solutions/15_traits/traits1.rs delete mode 100644 rustlings/solutions/15_traits/traits2.rs delete mode 100644 rustlings/solutions/15_traits/traits3.rs delete mode 100644 rustlings/solutions/15_traits/traits4.rs delete mode 100644 rustlings/solutions/15_traits/traits5.rs (limited to 'rustlings/solutions/15_traits') diff --git a/rustlings/solutions/15_traits/traits1.rs b/rustlings/solutions/15_traits/traits1.rs deleted file mode 100644 index 790873f..0000000 --- a/rustlings/solutions/15_traits/traits1.rs +++ /dev/null @@ -1,32 +0,0 @@ -// The trait `AppendBar` has only one function which appends "Bar" to any object -// implementing this trait. -trait AppendBar { - fn append_bar(self) -> Self; -} - -impl AppendBar for String { - fn append_bar(self) -> Self { - self + "Bar" - } -} - -fn main() { - let s = String::from("Foo"); - let s = s.append_bar(); - println!("s: {s}"); -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn is_foo_bar() { - assert_eq!(String::from("Foo").append_bar(), "FooBar"); - } - - #[test] - fn is_bar_bar() { - assert_eq!(String::from("").append_bar().append_bar(), "BarBar"); - } -} diff --git a/rustlings/solutions/15_traits/traits2.rs b/rustlings/solutions/15_traits/traits2.rs deleted file mode 100644 index 0db93e0..0000000 --- a/rustlings/solutions/15_traits/traits2.rs +++ /dev/null @@ -1,27 +0,0 @@ -trait AppendBar { - fn append_bar(self) -> Self; -} - -impl AppendBar for Vec { - fn append_bar(mut self) -> Self { - // ^^^ this is important - self.push(String::from("Bar")); - self - } -} - -fn main() { - // You can optionally experiment here. -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn is_vec_pop_eq_bar() { - let mut foo = vec![String::from("Foo")].append_bar(); - assert_eq!(foo.pop().unwrap(), "Bar"); - assert_eq!(foo.pop().unwrap(), "Foo"); - } -} diff --git a/rustlings/solutions/15_traits/traits3.rs b/rustlings/solutions/15_traits/traits3.rs deleted file mode 100644 index 3d8ec85..0000000 --- a/rustlings/solutions/15_traits/traits3.rs +++ /dev/null @@ -1,36 +0,0 @@ -trait Licensed { - fn licensing_info(&self) -> String { - "Default license".to_string() - } -} - -struct SomeSoftware { - version_number: i32, -} - -struct OtherSoftware { - version_number: String, -} - -impl Licensed for SomeSoftware {} -impl Licensed for OtherSoftware {} - -fn main() { - // You can optionally experiment here. -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn is_licensing_info_the_same() { - let licensing_info = "Default license"; - let some_software = SomeSoftware { version_number: 1 }; - let other_software = OtherSoftware { - version_number: "v2.0.0".to_string(), - }; - assert_eq!(some_software.licensing_info(), licensing_info); - assert_eq!(other_software.licensing_info(), licensing_info); - } -} diff --git a/rustlings/solutions/15_traits/traits4.rs b/rustlings/solutions/15_traits/traits4.rs deleted file mode 100644 index 3675b8d..0000000 --- a/rustlings/solutions/15_traits/traits4.rs +++ /dev/null @@ -1,35 +0,0 @@ -trait Licensed { - fn licensing_info(&self) -> String { - "Default license".to_string() - } -} - -struct SomeSoftware; -struct OtherSoftware; - -impl Licensed for SomeSoftware {} -impl Licensed for OtherSoftware {} - -fn compare_license_types(software1: impl Licensed, software2: impl Licensed) -> bool { - // ^^^^^^^^^^^^^ ^^^^^^^^^^^^^ - software1.licensing_info() == software2.licensing_info() -} - -fn main() { - // You can optionally experiment here. -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn compare_license_information() { - assert!(compare_license_types(SomeSoftware, OtherSoftware)); - } - - #[test] - fn compare_license_information_backwards() { - assert!(compare_license_types(OtherSoftware, SomeSoftware)); - } -} diff --git a/rustlings/solutions/15_traits/traits5.rs b/rustlings/solutions/15_traits/traits5.rs deleted file mode 100644 index 1fb426a..0000000 --- a/rustlings/solutions/15_traits/traits5.rs +++ /dev/null @@ -1,39 +0,0 @@ -trait SomeTrait { - fn some_function(&self) -> bool { - true - } -} - -trait OtherTrait { - fn other_function(&self) -> bool { - true - } -} - -struct SomeStruct; -impl SomeTrait for SomeStruct {} -impl OtherTrait for SomeStruct {} - -struct OtherStruct; -impl SomeTrait for OtherStruct {} -impl OtherTrait for OtherStruct {} - -fn some_func(item: impl SomeTrait + OtherTrait) -> bool { - // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - item.some_function() && item.other_function() -} - -fn main() { - // You can optionally experiment here. -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_some_func() { - assert!(some_func(SomeStruct)); - assert!(some_func(OtherStruct)); - } -} -- cgit v1.2.3