Coder Social home page Coder Social logo

sorting-fruits-kata's Introduction

Picking up Rust

Material for picking up Rust for experienced developers:

Material from the RustBridge organisation:
https://intro.rustbridge.com/en/intro/#1

Rustlings: lots of TDD style exercises to practice Rust
https://github.com/rust-lang/rustlings

The sorting fruits kata

A progressive kata to review Rust concepts by building a small apps step by step.

Given one fruit name (or fruit type) per line in the files in the assets folder, concatenate them in a single file, "fruits.txt", ordered alphabetically. The full list is very small, therefore it can be kept and manipulated in memory before writing it out to file.

Before using this repository, make sure you run cargo init .

Reference

https://en.wikipedia.org/wiki/Fruit https://github.com/dorfsmay/sorting-fruits-kata

Steps

001 Print list of files

Learnings

Instructions

  • create a function that:
    • take a String argument
    • print the list of files from the directory name given as the argument
  • unwrap everything for now
  • the function just prints, it does not return anything
  • In the main function, create a String variable containing "assets"
  • Use this variable to call your function

002 Result

Learnings

Instructions

  • Remove "unwrap"

003 Ownership

Learnings

Instructions

  • Make your main print "Files inside folder folder-name before calling the function
  • Note 1: You can create a reference to string literal, no need to convert to String
  • Note 2: note how you do not need to change the type of the variable for read_dir (automatic dereferencing)

004 Print from the array

Learnings

  • Rust Vectors and vec! macro
  • mutable variables
  • Rust guarding against non-initialised variables

Instructions

  • Make the function return a Vector of PathBuff
  • Keep using a loop to create the vector, don't jump into a turbo fish yet
  • Make main to print them

005 Return an Option

Learnings

Instructions

  • Add unit tests checkink for Some
  • decide if you want to user unwrap for the unit tests, or make tem return a Result
  • Make the function returning an Option
  • adjust main

006 Vector manipulation

Learnings

Instructions

  • Add a function to read the content of a file into a vector
  • make main concatenate the content of all the files into a single vector
  • make main sort the list of words (using the Vector sort)
  • make main print the entire list

sorting-fruits-kata's People

Contributors

dorfsmay avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.