Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
yansq authored Jan 8, 2025
2 parents 2a2970f + 078cdf6 commit 4cfb8e5
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 14 deletions.
36 changes: 36 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Copyright (c) 2024-present Rustfinity.
All Rights Reserved.

1. License Grant
Subject to the terms and conditions of this License, the Licensor hereby grants you a limited, non-exclusive, non-transferable, non-sublicensable right to view and use the software. This right is strictly for internal evaluation, testing, and development purposes only.

2. Restrictions

- You may not distribute, sublicense, sell, lease, rent, loan, or otherwise transfer the software or any portion of it to any third party without express written permission from the Licensor.
- You may not modify, adapt, or create derivative works of the software unless explicitly permitted by the Licensor in writing.
- You may not remove or alter any copyright notices, proprietary notices, trademarks, or other identifying marks from the software.

3. Ownership

- The Licensor retains all right, title, and interest in and to the software, including all intellectual property rights.
- No rights or licenses are granted by implication or estoppel.

4. Disclaimer of Warranty

- The software is provided on an “AS IS” basis without warranties or conditions of any kind, either express or implied, including, without limitation, warranties or conditions of merchantability, fitness for a particular purpose, or non-infringement.
- The software is provided "as is" and no guarantees or warranties of any kind are provided.
- You assume all responsibility and risk for the use of the software.

5. Limitation of Liability
To the maximum extent permitted by law, in no event shall the Licensor be liable for any direct, indirect, incidental, special, exemplary, or consequential damages. This includes, but is not limited to, procurement of substitute goods or services, loss of use, data, or profits, or business interruption, however caused and under any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of the software.

6. Termination

- This License is effective until terminated.
- Your rights under this License will terminate automatically without notice if you fail to comply with any of its terms.
- Upon termination, you must immediately cease all use of the software and destroy or return all copies of the software in your possession or control.

7. Entire Agreement
This License constitutes the entire agreement between you and the Licensor concerning the software and supersedes all prior or contemporaneous understandings regarding such subject matter. Any modifications to this License must be in writing and signed by both parties.

If you do not agree with the terms of this License, you are not allowed to use or access the software in any manner.
154 changes: 148 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,155 @@
![Rustfinity.com](/images/rustfinity-header.png)
[![Rustfinity Banner](./images/rustfinity-header.png)](https://rustfinity.com)

# Rustfinity

A repository for all the publicly available content for Rustfinity.
<p>
<a href="https://rustfinity.com"><img src="https://img.shields.io/badge/Rustfinity%20Docs-18181B?style=flat&logo=rust" alt="Website"></a>
<a href="https://github.com/dcodesdev/rustfinity.com/blob/main/LICENSE"><img src="https://img.shields.io/github/license/dcodesdev/rustfinity.com.svg?style=flat&colorA=18181B&colorB=28CF8D" alt="License"></a>
<a href="https://github.com/dcodesdev/rustfinity.com/issues"><img src="https://img.shields.io/github/issues/dcodesdev/rustfinity.com.svg?style=flat&colorA=18181B&colorB=28CF8D" alt="Issues"></a>
<a href="https://github.com/dcodesdev/rustfinity.com/pulls"><img src="https://img.shields.io/github/issues-pr/dcodesdev/rustfinity.com.svg?style=flat&colorA=18181B&colorB=28CF8D" alt="Pull Requests"></a>
</p>

## Crates
Rustfinity is an **interactive learning platform** dedicated to helping Rust developers of all levels learn and practice Rust programming concepts.
**[Visit our website → rustfinity.com](https://rustfinity.com)** to explore challenges, tutorials, and everything you need to level up your Rust skills!

- [CLI](crates/cli/)
> **Why Rustfinity?**
>
> - **Hands-on Learning**: Practice your Rust skills with real challenges in a fun environment.
> - **Comprehensive Exercises**: From basics to advanced topics—there’s something for everyone.
> - **Engaging Community**: Contribute, discuss, and grow alongside other Rust enthusiasts!
## Challenges
---

- [Challenges](challenges/)
## Table of Contents

- 🚀 [Getting Started](#-getting-started)
- 📂 [Folder Structure](#-folder-structure)
- [challenges/](#challenges)
- [crates/](#crates)
- 🤖 [Crates](#-crates-details)
- [cli](#cli)
- [rustfinity-runner](#rustfinity-runner)
- [syntest](#syntest)
- ❤️ [Contribute](#-contribute)
- 🏠 [Local Development](#-local-development)
- 🔗 [Follow Us](#-follow-us)
- ⚖️ [License](#-license)

---

## 🚀 Getting Started

1. **Head to [rustfinity.com](https://rustfinity.com)**
Explore available challenges and pick the ones you want to tackle.
2. **Try out the `cli` crate (optional)**
You can download challenges and practice them locally right from your terminal.
3. **Dive into the code**
Explore this repository to see how challenges and crates are structured.

---

## 📂 Folder Structure

```bash
.
├── challenges/
│ ├── challenge-1/
│ │ ├── description.md
│ │ ├── src/
│ │ │ ├── lib.rs
│ │ │ └── starter.rs
│ │ └── tests/
│ │ └── tests.rs
│ └── challenge-2/ (and so on...)
└── crates/
├── cli
├── rustfinity-runner
└── syntest
```

### <a name="challenges">challenges/</a>

This directory holds all the coding challenges served on [rustfinity.com](https://rustfinity.com). Feel free to submit new challenges, improve existing ones, or solve them locally using our CLI.

### <a name="crates">crates/</a>

This folder contains multiple Rust crates that power the Rustfinity platform.

---

## 🤖 <a name="crates-details">Crates</a>

### <a name="cli">`cli`</a>

- **What is it?**
The Rustfinity Command-Line Interface to help you **download, solve, and submit** Rustfinity challenges locally.
- **Key Features**
- Download any challenge directly to your local environment
- Submit solutions with `rustfinity submit` which redirects you to the challenge page with your solution

### <a name="rustfinity-runner">`rustfinity-runner`</a>

- **What is it?**
A crate designed for running challenge tests inside a secure Docker container.
- **Key Features**
- Spins up a temporary Docker container to safely execute user code
- Logs outputs and results from test runs
- Ensures a clean environment for each challenge submission

### <a name="syntest">`syntest`</a>

- **What is it?**
A specialized testing library built on top of Rust’s [`syn`](https://docs.rs/syn) library to analyze and validate Rust code syntax.
- **Key Features**
- Parse Rust AST (Abstract Syntax Tree) for testable patterns
- Provides an easy interface for writing **syntax-based** tests
- Helps ensure your Rust code meets style and syntactic guidelines

---

## ❤️ Contribute

We’d love your help! Whether it’s fixing bugs, adding challenges, or improving docs, every bit of help **matters**.

1. **Check out our [issues](https://github.com/dcodesdev/rustfinity.com/issues)**: Found a bug or want to suggest an enhancement? Open an issue!
2. **Fork & PR**: Fork the repo, make changes, and submit a pull request.
3. **Join our Discord**: [Join our Discord server](https://discord.gg/8GRcUqY48B) to discuss ideas, ask questions, or just hang out with the community.
4. **Spread the word**: Share Rustfinity with your friends, colleagues, or on social media.

---

## 🏠 Local Development

Ready to hack on Rustfinity locally? Here’s how:

```bash
# 1. Clone the repository
git clone https://github.com/dcodesdev/rustfinity.com.git
cd rustfinity.com

# 2. (Optional) Switch to a new branch for your work
git checkout -b my-new-feature

# 3. Explore and build
cargo build
```

We recommend installing [Docker](https://www.docker.com/) if you want to test the `rustfinity-runner` crate in a containerized environment.

---

## 🔗 Follow Us

Stay updated with the latest challenges, features, and announcements!

<p>
<a href="https://x.com/rustfinity"><img src="https://img.shields.io/badge/X-18181B?style=flat&logo=x&logoColor=white" alt="X"></a>
<a href="https://github.com/dcodesdev/rustfinity.com"><img src="https://img.shields.io/badge/GitHub-18181B?style=flat&logo=github&logoColor=white" alt="GitHub"></a>
<a href="https://discord.gg/8GRcUqY48B"><img src="https://img.shields.io/badge/Discord-18181B?style=flat&logo=discord&logoColor=white" alt="Discord"></a>
</p>

---

## ⚖️ License

This project is licensed under the [Rustfinity Proprietary License](https://github.com/dcodesdev/rustfinity.com/blob/main/LICENSE).
6 changes: 3 additions & 3 deletions challenges/animal-sanctuary-registry/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Hashmaps are a powerful data structure that allow you to store **key-value pairs**. In Rust, the `HashMap` type is provided that uses the a **hashing algorithm** called **SipHash** to store keys and values in a way that allows for **fast and secure** lookups. Think of them as a dictionary in Python or an object in JavaScript.

In this challenge, we want to build a sanctuary registry that allows us to manage animals in different sections of the sanctuary. We'll use a `HashMap` to store the sections as keys and a `Vec` to store the animals in each section. Each key is a section name `String` and each value is a list of animals in that section `Vev<String>`.
In this challenge, we want to build a sanctuary registry that allows us to manage animals in different sections of the sanctuary. We'll use a `HashMap` to store the sections as keys and a `Vec` to store the animals in each section. Each key is a section name `String` and each value is a list of animals in that section `Vec<String>`.

## Task

Expand All @@ -12,9 +12,9 @@ Your task is to implement the following functions:

1. `add_animal_to_section`: This function should add an animal to a section in the registry. If the section does not exist, it should be created. If the animal is already in the section, it should not be added again.

2. `get_animals_in_section`: This function should return a list of animals sorted **alphabetically** in a given section. If the section does not exist, it should return an empty list.
2. `get_animals_in_section`: This function should return a list of animals **sorted alphabetically** in a given section. If the section does not exist, it should return an empty list.

3. `get_all_animals`: This function should return a copy of the entire registry with all animals **sorted alphabetically** in each section.
3. `get_all_animals_sorted`: This function should return a copy of the entire registry with all animals **sorted alphabetically** in each section.

## Example

Expand Down
2 changes: 1 addition & 1 deletion challenges/control-flow/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ assert_eq!(result, "zero");

## Hints

- You can use the `if`, `else-if`, and `else` keywords to implement the control flow.
- You can use the `if`, `else if`, and `else` keywords to implement the control flow.
- Remember to return the result as a `String`.
1 change: 1 addition & 0 deletions challenges/declaring-variables/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ Then, calculate the area of a rectangle using the formula `area = width * height

- Use the `let` keyword to declare variables.
- Remember that variables declared with `let` are immutable by default.
- You do not need to explicitly annotate the types (e.g., `let width: u32 = 10;`) for the variables.
- Use multiplication `*` to calculate the area.
5 changes: 5 additions & 0 deletions challenges/find-the-first-palindrome/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ mod tests {
fn test_find_first_palindrome_edge_case() {
assert_eq!(find_first_palindrome(1, 1), Some(1));
}

#[test]
fn test_find_first_palindrome_negative_range() {
assert_eq!(find_first_palindrome(-1, 1), Some(0));
}
}
2 changes: 1 addition & 1 deletion challenges/graceful-error-handling/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ When you have a function that can fail, you can use the `Result` type to return

## Your task

In this challenges, you're given a function, `parse_percentage(input: &str) -> Result<u8, String>` that takes a string as input and returns a `Result` type. The function should parse the input string as a percentage and return the percentage as a `u8` if the input is valid. If the input is invalid, the function should return an error message as a `String`.
In this challenge, you're given a function, `parse_percentage(input: &str) -> Result<u8, String>` that takes a string as input and returns a `Result` type. The function should parse the input string as a percentage and return the percentage as a `u8` if the input is valid. If the input is invalid, the function should return an error message as a `String`.

Parsing from a string to a number can fail for many reasons. For example, the input string may not be a valid number, or it may be a valid number but not a valid percentage. Your task is to handle these errors gracefully and return an error message that explains what went wrong.

Expand Down
9 changes: 6 additions & 3 deletions challenges/ownership/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ In Rust, each value has a variable that's called its **owner**. There can only b

```rust
{
let s = String::from("hello"); // s is the owner of the String
// s is the owner of the String
let s = String::from("hello");
} // s goes out of scope and "hello" is dropped
```

Expand All @@ -30,11 +31,13 @@ You can create multiple **immutable references** to a value, but you cannot have
fn main() {
let s1 = String::from("hello");

let len = calculate_length(&s1); // borrow s1 as immutable
// Borrow s1 as immutable
let len = calculate_length(&s1);
println!("The length of '{}' is {}.", s1, len);
}

fn calculate_length(s: &String) -> usize { // s is an immutable reference to a String
// s is an immutable reference to a String
fn calculate_length(s: &String) -> usize {
s.len()
}
```
Expand Down

0 comments on commit 4cfb8e5

Please sign in to comment.