Skip to content

Instantly share code, notes, and snippets.

@rpivo
Last active July 7, 2021 22:34
Show Gist options
  • Save rpivo/6b1fdb879ee5a6e9168f750637dd33e4 to your computer and use it in GitHub Desktop.
Save rpivo/6b1fdb879ee5a6e9168f750637dd33e4 to your computer and use it in GitHub Desktop.
Calling Static Methods in Rust

Calling Static Methods in Rust

You can call a non-instance static method in Rust by using the :: separator.

Example:

impl Solution {
    pub fn return_empty_string() -> String {
        // returns ""
        return String::new();
    }
}

Note that many types have a new() function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment