A list of frequently used in Rust functions?

I tried AI to get the list, and it looks incomplete:

Frequently used Rust standard library (std) functions and methods include essential collection, option, and result handlers: vec![], println!(), clone(), unwrap(), iter(), map(), collect(), find(), format!(), and drop(). These core functions allow for efficient data manipulation, error handling, and memory management.

Frequently Used std Functions & Macros

  • Console I/O & Macros: println!(), format!(), panic!().
  • Memory Management: drop() (manually drop a value), mem::swap, mem::replace.
  • Iterator/Collection Methods (Vec, HashMap, Iter):
    • iter() / iter_mut(): Create iterators.
    • map() / filter_map(): Transform elements.
    • find() / any() / all(): Query collections.
    • collect(): Transform an iterator into a collection.
    • push() / pop(): Modify Vectors.
    • insert() / get() / entry(): Modify/access HashMaps.
  • Option & Result Handling:
    • unwrap() / expect(): Extract values, panicking on failure.
    • is_some() / is_none() / is_ok() / is_err(): Check types.
    • unwrap_or() / unwrap_or_default(): Handle defaults.
  • Type Conversion & Traits: clone(), to_string(), as_ref().

These utilities are part of the std prelude and are generally available in all Rust programs.

Does anybody have a comprehensive list of such functions, maybe based on own experience?

I need to integrate the list with IDE.

What exactly is your goal?

Why not use a LSP like rust-analyzer?

1 Like

I have the "Apple" disease. Fiends are always curious - why don't you buy just iPhone? Why don't you just go in Starbucks instead of brewing own coffee? Why don't you use Cargo instead of your own tool? Why do you program in Rust instead of using Python? Doctors do not give a clear answer what's a cause of the disease, and how to cure it. I wish to know the answer too.

1 Like

So you're trying to make a Rust IDE extension or autocomplete wordlist, I guess?

Edit: Oh, that's what you said in your first post.

If the goal is to make something which development experience reaches rust-analyzer's, I personally recommend making a fork of rust-analyzer's codebase instead.

If you just want a list of frequently used functions/macros, I don't feel like I have enogh experience to suggest some. But you can find out by surveying. e.g. Pick 100 random Rust repos on GitHub/GitLab, or the 200 most popular crates on lib.rs.[1] Download their source code. Write a small script to extract and count function frequency. I'd expect this to reveal some domain-specific functions that you haven't thought of (e.g. syn's quote! for proc macro crates).

There are some shortcuts, like docs.rs will link the used functions in the view source pages and you can take advantage of these marks. I don't know if that's acceptable usage though.


  1. I consider its recommendations more accurate than crates.io because as far as I know, the latter rates "most popular" more naively ↩︎

1 Like

I'm not sure, but maybe it would be possible to use crater to get a statistical overview over the "hottest" functions, methods and macros in Rust.

1 Like

if you want to make your own autocomplete tool i strongly reccomend you look into how lsp are developed and at least approximate that because using just a list of common metods is going to make it continuosly give you incorrect methods that do not compile

2 Likes

Is a fixed list of autocompletions the only option for you or is it possible to write an extension for your ide that can run arbitrary code, but just doesn't support the lsp protocol. If the latter, you could try using the rust-analyzer crates that are behind the LSP facade. They are published as ra_ap_* on crates.io and are used already by other projects. For example evcxr uses it to get the types of variables: evcxr/evcxr/src/rust_analyzer.rs at main · evcxr/evcxr · GitHub

1 Like

LSP looks certainly interesting. I am only a bit biased to Microsoft. But since I can implement the server in Kotlin, it will tremendously save a development time. From other side, I am looking in MCP (Model Context Protocol), since I can omit a particular details of the code and simply provide a ready to integrate solutions. Thank you all for your thoughts.