rust-lang / rustlings

:crab: Small exercises to get you used to reading and writing Rust code!
https://rustlings.cool
MIT License
52.75k stars 10.02k forks source link

C++ STL equivalent in Rust? #1382

Closed apoorv-2204 closed 1 year ago

apoorv-2204 commented 1 year ago

do we have c++ stl equivalent in rust?? Can we completely switch to Rust for competitive programming? or stick with c++

cyril-marpaud commented 1 year ago

This link describes the C++ STL.

Among others, it states that:

Some of the key components of the STL include:

  • Containers: The STL provides a range of containers, such as vector, list, map, set, and stack, which can be used to store and manipulate data.
  • Algorithms: The STL provides a range of algorithms, such as sort, find, and binary_search, which can be used to manipulate data stored in containers.
  • Iterators: Iterators are objects that provide a way to traverse the elements of a container. The STL provides a range of iterators, such as forward_iterator, bidirectional_iterator, and random_access_iterator, that can be used with different types of containers.
  • Function Objects: Function objects, also known as functors, are objects that can be used as function arguments to algorithms. They provide a way to pass a function to an algorithm, allowing you to customize its behavior.
  • Adapters: Adapters are components that modify the behavior of other components in the STL. For example, the reverse_iterator adapter can be used to reverse the order of elements in a container.

In Rust:

In short, what you are looking for is already part of the Rust Standard Library.

apoorv-2204 commented 1 year ago

This link describes the C++ STL.

Among others, it states that:

Some of the key components of the STL include:

  • Containers: The STL provides a range of containers, such as vector, list, map, set, and stack, which can be used to store and manipulate data.
  • Algorithms: The STL provides a range of algorithms, such as sort, find, and binary_search, which can be used to manipulate data stored in containers.
  • Iterators: Iterators are objects that provide a way to traverse the elements of a container. The STL provides a range of iterators, such as forward_iterator, bidirectional_iterator, and random_access_iterator, that can be used with different types of containers.
  • Function Objects: Function objects, also known as functors, are objects that can be used as function arguments to algorithms. They provide a way to pass a function to an algorithm, allowing you to customize its behavior.
  • Adapters: Adapters are components that modify the behavior of other components in the STL. For example, the reverse_iterator adapter can be used to reverse the order of elements in a container.

In Rust:

In short, what you are looking for is already part of the Rust Standard Library.

So I can say goodbye to C++? as everything is there in Rust already part of the standard library ? we dont need any crates?. Beacuse in online judjes like codechef, leetcode, spoj, codeforces, they dont allow crates.

cyril-marpaud commented 1 year ago

Well, I really couldn't say, it depends on what you intend to do but a lot of people already use Rust for competitive programming. There even is an advent_of_code crate for instance, and you can find many other examples.

On the other hand, it's a little weird to me that you're asking for a "batteries-included competitive programming language" because it sounds like you're looking for a language that will give you an advantage over your competitors.

I personally believe that Rust and its ecosystem will help anyone be more productive but in the end, only you can answer that question by trying it. Be aware that the learning curve is a little steeper than for other languages, though.

shadows-withal commented 1 year ago

All that aside, this is a discussion forum for Rustlings. Your question might be better suited to one of the more general discussion forums, such as the Users forum. Closing this as off-topic.

apoorv-2204 commented 1 year ago

Well, I really couldn't say, it depends on what you intend to do but a lot of people already use Rust for competitive programming. There even is an advent_of_code crate for instance, and you can find many other examples.

On the other hand, it's a little weird to me that you're asking for a "batteries-included competitive programming language" because it sounds like you're looking for a language that will give you an advantage over your competitors.

I personally believe that Rust and its ecosystem will help anyone be more productive but in the end, only you can answer that question by trying it. Be aware that the learning curve is a little steeper than for other languages, though.

sounds like you're looking for a language that will give you an advantage over your competitors.

I hope you are not oblivious to the original question.

apoorv-2204 commented 1 year ago

All that aside, this is a discussion forum for Rustlings. Your question might be better suited to one of the more general discussion forums, such as the Users forum. Closing this as off-topic.

Right, I really needed to have an insight. I just dont want to go back to C++.

apoorv-2204 commented 1 year ago

Thank you everyone!