1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2024-09-20 00:08:06 +02:00
rustlings/exercises/15_traits/traits4.rs

36 lines
798 B
Rust
Raw Normal View History

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