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
Sardana integration into the Jupyter ecosystem.

sardana-jupyter Sardana integration into the Jupyter ecosystem.

Marc Espín 1 Dec 23, 2021
🏆 A ranked list of awesome Python open-source libraries and tools. Updated weekly.

Best-of Python ?? A ranked list of awesome Python open-source libraries & tools. Updated weekly. This curated list contains 230 awesome open-source pr

Machine Learning Tooling 2.7k Jan 3, 2023
App to decide weekly winners in H2H 1 Win (9 Cat)

Fantasy Weekly Winner for H2H 1 Win (9 Cat) Yahoo Fantasy API Read

Sai Atmakuri 1 Dec 31, 2021
A Python application that helps users determine their calorie intake, and automatically generates customized weekly meal and workout plans based on metrics computed using their physical parameters

A Python application that helps users determine their calorie intake, and automatically generates customized weekly meal and workout plans based on metrics computed using their physical parameters

Anam Iqbal 1 Jan 13, 2022
A code ecosystem that helps to find the equate any formula.

A code ecosystem that helps to find the equate any formula. The good part here is that the code finds the formula needed and/or operates on a formula (performs algebra) on it to give you an answer.

SubtleCoder 1 Nov 23, 2021
peace-performance (Rust) binding for python. To calculate star ratings and performance points for all osu! gamemodes

peace-performance-python Fast, To calculate star ratings and performance points for all osu! gamemodes peace-performance (Rust) binding for python bas

null 9 Sep 19, 2022
A tool to assist in code raiding in rust

Kodelock a tool to assist in code raiding in rust This tool is designed to be used on a second monitor. This tools will allow you to see a easily read

null 3 Oct 27, 2022
Python binding to rust zw-fast-quantile

zw_fast_quantile_py zw-fast-quantile python binding Installation pip install zw_fast_quantile_py Usage import zw_fast_quantile_py

Paul Meng 1 Dec 30, 2021
Reload all Blender add-on modules

Reload-Addon This add-on creates a list of the modules that the add-on selected in the drop-down menu contains and reloads them with the keyboard shor

null 2 Dec 2, 2021
Import modules and files straight from URLs.

Import Python code from modules straight from the internet.

Nate 2 Jan 15, 2022
Python communism - A module for initiating the communist revolution in each of our python modules

Python communist revolution A man once said to abolish the classes or something

null 758 Jan 3, 2023
This repository holds those infrastructure-level modules, that every application requires that follows the core 12-factor principles.

py-12f-common About This repository holds those infrastructure-level modules, that every application requires that follows the core 12-factor principl

Tamás Benke 1 Dec 15, 2022
Odoo modules related to website/webshop

Website Apps related to Odoo it's website/webshop features: webshop_public_prices: allow configuring to hide or show product prices and add to cart bu

Yenthe Van Ginneken 9 Nov 4, 2022
Originally used during Marketplace.tf's open period, this program was used to get the profit of items bought with keys and sold for dollars.

Originally used during Marketplace.tf's open period, this program was used to get the profit of items bought with keys and sold for dollars. Practically useless for me now, but can be used as an example of tkinter.

BoggoTV 1 Dec 11, 2021
These are the scripts used for the project of ‘Assembly of a pan-genome for global cattle reveals missing sequence and novel structural variation, providing new insights into their diversity and evolution history’

script-SV-genotyping These are the scripts used for the project of ‘Assembly of a pan-genome for global cattle reveals missing sequence and novel stru

null 2 Aug 26, 2022
A Linux webcam plugin for BGMv2 as used in our demos.

The goal of this repository is to supplement the main Real-Time High Resolution Background Matting repo with a working demo of a videoconferencing plu

Andrey Ryabtsev 144 Dec 27, 2022
tidevice can be used to communicate with iPhone device

h 该工具能够用于与iOS设备进行通信, 提供以下功能 截图 获取手机信息 ipa包的安装和卸载 根据bundleID 启动和停止应用 列出安装应用信息 模拟Xcode运行XCTest,常用的如启动WebDriverAgent测试

Alibaba 1.8k Dec 30, 2022
Code for the manim-generated scenes used in 3blue1brown videos

This project contains the code used to generate the explanatory math videos found on 3Blue1Brown. This almost entirely consists of scenes generated us

Grant Sanderson 4.1k Jan 2, 2023
HPomb Is Socail Engineering Tool , Used For Bombing , Spoofing and Anonymity Available For Linux And Android(Termux)

HPomb v2020.02 Coming Soon Created By Secanonm HPomb Is Socail Engineering Tool , Used For Bombing , Spoofing and Anonymity Available For Linux And An

Secanonm 10 Jul 25, 2022