Hi all. I have this common behaviors for products but Rust won't let me access fields in&self. Other than blindly copy-pasting duplicate functions, how can I work around this? Note that later in the project I will have multiple kinds of hardware and many of them; same goes for software. I do not want to copy-paste anything.
struct Manufacturer<'a>
{
name: &'a str
}
struct Date<'a>
{
//YYYYMMDD
value: &'a [u8; 8]
}
trait product
{
fn get_manufacturer<'a>(&self) -> Manufacturer<'a>
{
self.manufacturer
}
fn get_release_date<'a>(&self) -> Date<'a>
{
self.release_date
}
fn get_model<'a>(&self) -> &'a str
{
self.model
}
}
struct Hardware<'a>
{
manufacturer: Manufacturer<'a>,
release_date: Date<'a>,
model: &'a str
}
impl <'a> product for Hardware<'a>
{
}
struct Software<'a>
{
manufacturer: Manufacturer<'a>,
release_date: Date<'a>,
model: &'a str
}
impl <'a> product for Software<'a>
{
}
struct System<'a>
{
hardarray: Vec<Hardware<'a>>,
softarray: Vec<Software<'a>>
}
fn main()
{
}