rustlings/exercises/15_traits/traits4.rs

36 lines
798 B
Rust
Raw Normal View History

2024-05-22 16:04:12 +03:00
trait Licensed {
2022-02-25 19:41:10 +03:00
fn licensing_info(&self) -> String {
2024-06-27 13:23:33 +03:00
"Default license".to_string()
2022-02-25 19:41:10 +03:00
}
}
2024-06-27 13:23:33 +03:00
struct SomeSoftware;
struct OtherSoftware;
2022-02-25 19:41:10 +03:00
impl Licensed for SomeSoftware {}
impl Licensed for OtherSoftware {}
2024-06-27 13:23:33 +03:00
// TODO: Fix the compiler error by only changing the signature of this function.
fn compare_license_types(software1: ???, software2: ???) -> bool {
software1.licensing_info() == software2.licensing_info()
2022-02-25 19:41:10 +03:00
}
fn main() {
// You can optionally experiment here.
}
2022-02-25 19:41:10 +03:00
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn compare_license_information() {
2024-06-27 13:23:33 +03:00
assert!(compare_license_types(SomeSoftware, OtherSoftware));
2022-02-25 19:41:10 +03:00
}
#[test]
fn compare_license_information_backwards() {
2024-06-27 13:23:33 +03:00
assert!(compare_license_types(OtherSoftware, SomeSoftware));
2022-02-25 19:41:10 +03:00
}
}