Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Very tiny suggestion about Rust grammar #2

Open
fzyzcjy opened this issue Jun 28, 2022 · 0 comments
Open

Very tiny suggestion about Rust grammar #2

fzyzcjy opened this issue Jun 28, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@fzyzcjy
Copy link

fzyzcjy commented Jun 28, 2022

@y-young

When very briefly wandering around this project, attracted by @y-young, I see a very very tiny issue, and just post it here as a small practice to Rust:

pub fn add_path(&mut self, path: &String, svc_ip: &Ipv4Addr, svc_port: &u16) {

    pub fn add_path(&mut self, path: &String, svc_ip: &Ipv4Addr, svc_port: &u16) {
        self.paths.push(IngressPath {
            path: path.to_owned(),
            ip: svc_ip.to_owned(),
            port: svc_port.to_owned(),
        });
    }

I am not sure about the following:

  1. Is &str better than &String?
  2. Is u16 more efficient than &u16 when passing an argument?
  3. If the user of this method do not need path/src_ip anymore, currently the add_path still makes a copy of it. If we change the signature to path: String and remove to_owned(), maybe we can remove a memory copy in such case.
@fzyzcjy fzyzcjy changed the title Very tiny suggestion Very tiny suggestion about Rust grammar Jun 28, 2022
@y-young y-young added the enhancement New feature or request label Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants