Is it possible to require that a struct have a particular field as part of a trait? I am doing some web automation in Rust with the thirtyfour_sync crate. I want to write some traits with default implementations for page objects that will implement them. Basically, I know for a fact that every struct that is going to implement this trait will have a field called "driver" that holds a reference to a WebDriver struct. I want to use this driver field in my default implementation of the trait.
error[E0609]: no field `driver` on type `&Self`
--> src\base_order_details.rs:13:30
|
10 | / pub trait BaseOrderDetails {
11 | |
12 | | fn oid(&self) -> WebDriverResult<String> {
13 | | let oid_title = self.driver.find_element(By::XPath("//*[text()=\"Order ID:\"]"))?;
| | ^^^^^^
... |
Is there a way to let the compiler know that anything implementing this trait will have a field driver of type &WebDriver?