A weekly dive into commonly used modules in the Rust ecosystem, with story flavor!

Overview

Rust Module of the Week

A weekly dive into commonly used modules in the Rust ecosystem, with story flavor!

Build status

  • Release
    • Rust examples
    • Content
  • Draft
    • Rust examples
    • Content

The goal

The goal of this project is to bring the same concept as PyMOTW to the Rust world. PyMOTW was an invaluable resource for me when I was learning Python years ago, and I hope that I can help someone in a similar way. Each week we'll dive into a module and explore some of the functionality that we can find there while following along the adventures of some colourful characters.

Why the story?

I have always found that I learn better when there's a story behind something I'm learning, a purpose. I've looked at my fair share of documentation but I've found that a lot of code samples can be hard to follow without broader context. So I've decided that every issue will include the story of one or more characters and their problems that only Rust can solve.

Examples

See the examples README for how to run them.

Contributing

Feel free to fork and open Pull Requests about any past or potential future content! I would especially welcome any code feedbacks as I'm sure there'll be lots of chances to improve my code. A proper development guide is planned.

Comments
  • [Error] Compilation error in the first example

    [Error] Compilation error in the first example

    Hi,

    First of all - great initiative.

    I'm a complete Rust noob and this is exactly what I was looking for - an easily digestible, short articles on Rust stdlib.

    Now, when I try to execute the first example:

    use std::{fs, io};
    
    const PHOTO_HOME: &str = "/home/user/motw/week-1/";
    
    fn main() {
        let entries = fs::read_dir(PHOTO_HOME)?
            .map(|entry_res| entry_res.map(|entry| entry.path()))
            .collect::<Result<Vec<_>, io::Error>>()?;
    
        println!("{:?}", entries);
    }
    

    I get the following error:

    error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
      --> src/main.rs:6:43
       |
    5  | / fn main() {
    6  | |     let entries = fs::read_dir(PHOTO_HOME)?
       | |                                           ^ cannot use the `?` operator in a function that returns `()`
    7  | |         .map(|entry_res| entry_res.map(|entry| entry.path()))
    8  | |         .collect::<Result<Vec<_>, io::Error>>()?;
    9  | |
    10 | |     println!("{:?}", entries);
    11 | | }
       | |_- this function should return `Result` or `Option` to accept `?`
       |
       = help: the trait `FromResidual<Result<Infallible, std::io::Error>>` is not implemented for `()`
       = note: required by `from_residual`
    
    error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
      --> src/main.rs:8:48
       |
    5  | / fn main() {
    6  | |     let entries = fs::read_dir(PHOTO_HOME)?
    7  | |         .map(|entry_res| entry_res.map(|entry| entry.path()))
    8  | |         .collect::<Result<Vec<_>, io::Error>>()?;
       | |                                                ^ cannot use the `?` operator in a function that returns `()`
    9  | |
    10 | |     println!("{:?}", entries);
    11 | | }
       | |_- this function should return `Result` or `Option` to accept `?`
       |
       = help: the trait `FromResidual<Result<Infallible, std::io::Error>>` is not implemented for `()`
       = note: required by `from_residual`
    

    Version of Rust in use is:

    stable-x86_64-unknown-linux-gnu (default)
    rustc 1.54.0 (a178d0322 2021-07-26)
    

    Could you provide hints on what could be wrong in my example?

    Thanks in advance!

    opened by matejrisek 2
  • Fix clippy lints

    Fix clippy lints

    In group_files_by_date the clone is not needed. or_insert_withis more efficient in the case where a value already exists, because the closure or function provided to it are only executed if needed, while or_insert always creates the value.

    BTW keep up the good work. I really enjoyed those posts! :)

    opened by Lesstat 1
  • Alternative implementation of visit_dirs

    Alternative implementation of visit_dirs

    fn visit_dirs(dir: &Path) -> io::Result<Vec<PathBuf>> {
        let mut stack = vec![fs::read_dir(dir)?];
        let mut files = vec![];
        while let Some(dir) = stack.last_mut() {
            match dir.next().transpose()? { // r: dir.find_map(|r| r.ok())
                None => {
                    stack.pop();
                }
                Some(dir) if dir.file_type().map_or(false, |t| t.is_dir()) => {
                    stack.push(fs::read_dir(dir.path())?); // stack.extend(fs::read_dir(dir.path()))
                }
                Some(file) => files.push(file.path()),
            }
        }
        Ok(files)
    }
    

    Recursion in Rust isn't specially optimised, so iterative solutions are often faster (in this case 3x). I think it would be good to make a note of this.

    Also, it's often better to just ignore errors returned from the ReadDir since they can have different permission flags etc. In these cases discarding the rest of the results can be overly pessimistic.

    opened by Plecra 1
  • Wrapping up some build automation

    Wrapping up some build automation

    As mentioned in #7 I wanted to have a clean build and release process. It's working for the draft branch, now it's time to bring it to the main branch before content changes/suggestions come in.

    opened by slyons 0
  • Enable continuous testing for examples

    Enable continuous testing for examples

    Enable continuous testing by some means. Whether through doctests or unit tests it would behoove us to have automatic testing and use it as a barrier to any merges.

    opened by slyons 0
  • Run code samples in CI and in the browser

    Run code samples in CI and in the browser

    #9 addresses a bug in one of the code samples. That made me thinking.

    What if we the examples can be tested automatically, similar to Rust's doc tests? Than issue like the one reported in #9 can be prevented.

    And what do you think about making the code sample executable in the web browser? The rust book offers that for many of it's examples.

    opened by OrangeTux 1
  • # std::fs Part 2

    # std::fs Part 2

    Rudgal gets serious about organizing. Will have to include some sort of generating function so the moving/organizing can be demonstrated.

    • DirBuilder
    • Permissions
    • Copying/removing files.
    opened by slyons 0
Releases(published)
Owner
Scott Lyons
Scott Lyons
Stop ask your soraka to ult you, just ult yourself

Lollo's auto-ultimate script Are you tired of your low elo friend who can't ult you with soraka when you ask for it? Use Useless Support and just ult

9 Oct 20, 2022
Python project that aims to discover CDP neighbors and map their Layer-2 topology within a shareable medium like Visio or Draw.io.

Python project that aims to discover CDP neighbors and map their Layer-2 topology within a shareable medium like Visio or Draw.io.

3 Feb 11, 2022
Automated GitHub profile content using the USGS API, Plotly and GitHub Actions.

Top 20 Largest Earthquakes in the Past 24 Hours Location Mag Date and Time (UTC) 92 km SW of Sechura, Peru 5.2 11-05-2021 23:19:50 113 km NNE of Lobuj

Mr. Phantom 28 Oct 31, 2022
IOP Support for Python (Experimental)

TAGS Experimental IOP Framework for Python WARNING: Currently, this project has NO EXCEPTION HANDLING. USE AT YOUR OWN RISK! I. Introduction to Interf

1 Oct 22, 2021
🤖🧭Creates google-like navigation menu using python-telegram-bot wrapper

python telegram bot menu pagination Makes a google style pagination line for a list of items. In other words it builds a menu for navigation if you ha

Sergey Smirnov 9 Nov 27, 2022
A simple interface to help lazy people like me to shutdown/reboot/sleep their computer remotely.

🦥 Lazy Helper ! A simple interface to help lazy people like me to shut down/reboot/sleep/lock/etc. their computer remotely. - USAGE If you're a lazy

MeHDI Rh 117 Nov 30, 2022
A lightweight solution for local Particle development.

neopo A lightweight solution for local Particle development. Features Builds Particle projects locally without any overhead. Compatible with Particle

Nathan Robinson 19 Jan 01, 2023
A Python Perforce package that doesn't bring in any other packages to work.

P4CMD 🌴 A Python Perforce package that doesn't bring in any other packages to work. Relies on p4cli installed on the system. p4cmd The p4cmd module h

Niels Vaes 13 Dec 19, 2022
CALPHAD tools for designing thermodynamic models, calculating phase diagrams and investigating phase equilibria.

CALPHAD tools for designing thermodynamic models, calculating phase diagrams and investigating phase equilibria.

pycalphad 189 Dec 13, 2022
⏰ Shutdown Timer is an application that you can shutdown, restart, logoff, and hibernate your computer with a timer.

Shutdown Timer is a an application that you can shutdown, restart, logoff, and hibernate your computer with a timer. After choosing an action from the

Mehmet Güdük 5 Jun 27, 2022
NewsBlur is a personal news reader bringing people together to talk about the world.

NewsBlur NewsBlur is a personal news reader bringing people together to talk about the world.

Samuel Clay 6.2k Dec 29, 2022
Pattern Matching for Python 3.7+ in a simple, yet powerful, extensible manner.

Awesome Pattern Matching (apm) for Python pip install awesome-pattern-matching Simple Powerful Extensible Composable Functional Python 3.7+, PyPy3.7+

Julian Fleischer 97 Nov 03, 2022
take home quiz

guess the correlation data inspection a pretty normal distribution train/val/test split splitting amount .dataset: 150000 instances ├─8

HR Wu 1 Nov 04, 2021
MuMMI Core is the underlying infrastructure and generalizable component of the MuMMI framework

MuMMI Core is the underlying infrastructure and generalizable component of the MuMMI framework, which facilitates the coordination of massively parallel multiscale simulations.

4 Aug 17, 2022
Simple calculator made in python

calculator Uma alculadora simples feita em python CMD, PowerShell, Bash ✔️ Início 💻 apt-get update apt-get upgrade -y apt-get install python git git

Spyware 8 Dec 28, 2021
System Information Utility With Python

System-Information-Utility This is a simple utility, for the terminal, which allows you to find out information about your PC. It's very easy to run t

2 Apr 15, 2022
Performance monitoring and testing of OpenStack

Browbeat Browbeat is a performance tuning and analysis tool for OpenStack. Browbeat is free, Open Source software. Analyze and tune your Cloud for opt

cloud-bulldozer 83 Dec 14, 2022
An extended, game oriented, turtle

Burtle A Better TURTLE. Makes making games easier. write less do more!! Documentation & guide: https://alannxq.github.io/burtle/ Installation pip inst

5 May 19, 2022
tgEasy | Easy for a Brighter Shine | Monkey Patcher Addon for Pyrogram

tgEasy | Easy for a Brighter Shine | Monkey Patcher Addon for Pyrogram

Jayant Hegde Kageri 35 Nov 12, 2022
Two predictive attributes (Speed and Angle) and one attribute target (Power)

Two predictive attributes (Speed and Angle) and one attribute target (Power). A container crane has the function of transporting containers from one point to another point. The difficulty of this tas

Astitva Veer Garg 1 Jan 11, 2022