rustlings/exercises/15_traits/traits4.rs

36 lines
798 B
Rust
Raw Normal View History

2024-05-22 09:04:12 -04:00
trait Licensed {
2022-02-25 11:41:10 -05:00
fn licensing_info(&self) -> String {
2024-06-27 06:23:33 -04:00
"Default license".to_string()
2022-02-25 11:41:10 -05:00
}
}
2024-06-27 06:23:33 -04:00
struct SomeSoftware;
struct OtherSoftware;
2022-02-25 11:41:10 -05:00
impl Licensed for SomeSoftware {}
impl Licensed for OtherSoftware {}
2024-06-27 06:23:33 -04: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 11:41:10 -05:00
}
fn main() {
// You can optionally experiment here.
}
2022-02-25 11:41:10 -05:00
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn compare_license_information() {
2024-06-27 06:23:33 -04:00
assert!(compare_license_types(SomeSoftware, OtherSoftware));
2022-02-25 11:41:10 -05:00
}
#[test]
fn compare_license_information_backwards() {
2024-06-27 06:23:33 -04:00
assert!(compare_license_types(OtherSoftware, SomeSoftware));
2022-02-25 11:41:10 -05:00
}
}