Giter VIP home page Giter VIP logo

rust-playground's Introduction

Rust Playground: data structure, algorithms, threads, etc.

This repository shows some examples of rust code for common coding problems. As rust is different from other programming languages, this is useful to have some patterns and code examples to translate what we know in this new paradigm.

How to use it?

git clone https://github.com/juli1/rust-playground.git
cd rust-playground
cargo run --bin animals
cargo run --bin main
cargo run --bin threads-unsafe
cargo run --bin threads-channel
cargo run --bin threads-rwlock
cargo test

Rust concepts

This code illustrates the following rust concepts:

Code samples

Traits

The file src/animals.rs shows a very basic example of how to define traits when defining a new structure Animals.

Data Structure

LinkedList

The file src/listnode.rs is a quick implementation of a linkedlist with rust. The ListNode struct is used in src/main.rs

Note that this implementation also implements:

  • An iterator so that you can play like for v in node.iter() { println!("{}", n
  • The Display trait to display a listnode and other next nodes so you can just do let n = ListNode::new(0); println!("treenode: {}", n);

Binary Tree

The file src/tree.rs is a quick implementation of a binary tree with rust. The TreeNode struct is used in src/main.rs

Trie

The file src/trie.rs is an implementation of a trie in Rust. The TrieNode struct is used in src/main.rs to insert or search for words.

Threads

Unsafe thread, communication through global variables

The file src/threads-unsafe.rs is a use of threads with unsafe operations (use of a global variable being modified).

Thread communication through channels

The file src/threads-channel.rs is a use of threads with channels.

Thread communication through using RwLock

The file src/threads-rwlock.rs is an example of use of rwlock between multiple readers and one writer.

Thread with conditional variable

The file src/threads-condvar.rs shows how to use a conditional variable with Rust. It spins 6 threads and synchronize their start using a conditional variable.

Crates being used/tested

Mime guess

Try to guess the MIME type of a file. You can see the file there: src/mime-guess.rs.

Useful resources

rust-playground's People

Contributors

juli1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

amilajack

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.