Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to define an associated functions named "new" that don’t have self as their first parameter

I’m getting the following error during cargo build. And I’m not sure how to resolve this.

error: not &self method
  --> src/new_service.rs:20:18
   |
20 |     pub async fn new() -> Self {
   |                  ^^^

relevant part of src/new_service.rs:

pub struct Service {
    start: Event,
    collections: Vec<Collection>,
    clients: Vec<Client>,
}

#[dbus_interface(name ="org.freedesktop.Secret.Service")]
impl Service {
    pub async fn new() -> Self {
        Service {
            start: event_listener::Event::new(),
            collections: Vec::new(),
            clients: Vec::new(),
        }
    }
.....

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can have multiple impl blocks for the same type, and that looks needed here since new wouldn’t be a callable DBus method. Try structuring your code like so:

pub struct Service {
    start: Event,
    collections: Vec<Collection>,
    clients: Vec<Client>,
}

impl Service {
    pub fn new() -> Self {
        Service {
            start: event_listener::Event::new(),
            collections: Vec::new(),
            clients: Vec::new(),
        }
    }
}

#[dbus_interface(name ="org.freedesktop.Secret.Service")]
impl Service {
    .....
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading