I'm trying to build a CLI to do automate some repeated tasks while building some big projects, and for that I'm trying to do some operations on the files and dirs. So my question is around this, is it better to use the std::fs API provided by the core library of rust, or it would be more beneficial to use the pre made commands in the OS level to make those tasks?
If possible, try to use functions from the standard library rather than assuming you'll have access to commands like rm or cp or mkdir. Assuming you'll have access to all the same programs and that they'll always behave the same is why so many projects work fine on Linux and MacOS, but crash when running on Windows.
Have a look at the xtask pattern for doing these sorts of management tasks. You might also want to use the xshell crate for the low level filesystem operations.
It's less common, but you can also see Linux and macOS working differently. Linux distributions usually ship with GNU command-line programs, whereas macOS’s are descended from BSD (and occasionally have their own Apple-specific extensions or quirks). This often shows up in specific commands having slightly different options.
So what i understand from u're reply is the most suitable way to do this kinda of operations using the core library of rust, since i can benefit the cross platform compatibility with it. right?
It's also going to be faster 9 times out of 10, but considering we're talking about operations that are normally measured using milliseconds, I doubt anyone will care.