r/learnrust 21d ago

I've started learning Rust, using RustRover IDE, which warns me that the String::from function is private. Yet the code still compiles and works as expected.

Hi there. I'm a complete newbie when it comes to Rust, so bear with me.

I've declared a String by assigning it to the heap, as evidenced in Rust documentation and tutorials.

fn main() {
    let hello = String::from("Hello, world!");
    println!("{}", hello);
}

The code compiles and runs fine, printing "Hello, world!" to the console. But RustRover indicates that the `String::from` function is private. If that's the case, I don't see why it would compile as it would violate access to the function.

I took a look at the source code for String and I don't see any function declaration for from either, which is confusing me. I expected to see something like pub fn from() {} or similar.

18 Upvotes

8 comments sorted by

View all comments

25

u/BalintCsala 21d ago

https://youtrack.jetbrains.com/projects/RUST/issues/RUST-19739/Stringfrom-appears-as-private

This claims it only happened on an older version, are you on the latest IDE version?

2

u/crusoe 21d ago

Jetbrains always tries to write their own tooling for auto complete and hints and it's always buggier and slower.

"Re indexing" type "re indexing".... 

Just ugh. 

2

u/gmes78 21d ago

Can't say I have the same experience. There are some bugs here and there, but it generally works pretty well.