Giter Club home page Giter Club logo

lifetimekata's Introduction

LifetimeKata

Welcome to LifetimeKata, a set of exercises which you can use to improve your understanding of lifetimes in Rust. While many tasks involve writing compiling code, some will also involve creating specific errors.

You should complete the kata in order, as they increase in difficulty, and depend on previous kata.

Getting Started

Clone this repository:

$ git clone https://www.github.com/tfpk/lifetimekata/

Most exercises are run in two steps:

$ cargo build --package ex04

And then either:

$ cargo test --package ex04

or:

$ cargo run --package ex04

depending on whether it's a binary or a library.

lifetimekata's People

Contributors

angusgmorrison avatar bestgopher avatar ctm avatar fmzbl avatar insideoutclub avatar nkysg avatar parker-codes avatar s1ck avatar skaunov avatar spanishpear avatar tfpk avatar youmoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

lifetimekata's Issues

Investigate adding a chapter on HRTBs

As suggested by @ctm :

I think lifetimekata would benefit from a chapter on HRTBs
I've had to use them every once in a while, but when I do so, it involves a bunch of trial and error and/or web searching.

Ch8 Finale task definition

Can we improve task definition so that limitations would be obvious from the start? It's my bad, I wasn't reading thorough enough, but staring long enough at Matcher::new signature output I decided that there's no way it could return None. Implemented it the way unmatched parenthesis go to RawText(_), and of course smashed into broken_matcher() test.

It's just a piece of feedback... Do you feel like that this detail deserve few words in the chapter?

Provide a solution for the first part of exercise 4

In chapter 4, the first part of the exercise asks the reader to explain why an error occurs, however there is no solution to this part of the exercise. Therefore the reader may be unsure whether their answer is correct. This can be remedied by either adding a click-and-reveal solution/answer, or including the answer in the solutions subdirectory

Claim of lifetime sizes in 00_welcome

Towards the end of the first chapter, once the 'variable and 'reference lifetimes has been established, there is the following statement:

We call a region of code where a variable exists a "lifetime". We can give lifetimes names using the syntax 'name. So if we call the variable's lifetime 'variable, and the reference's lifetime 'reference, we can then formally say that for any variable that references another variable, 'variable must be larger than 'reference.

The last part of this statement is confusing to me because it does not seem to be true for all cases.

Let's say in the code example, that the inner scope of 'variable is expanded to include the if let statement:

fn main() {
    let mut my_reference: Option<&i32> = None;

    // Starting a scope.
    {
        // my_variable created                               // \ \
        let my_variable: i32 = 7;                            // | |
        my_reference = Some(&my_variable);                   // | |- my_variable exists here. ('variable)
        // At the end of the scope, `my_variable` is dropped // | |
        drop(my_variable);                                   // | |
        // my variable destroyed                             // | /
    // inner scope does not stop here }
                                                             // |
    if let Some(reference) = my_reference {                  // |
        println!("{}", reference);                           // |
    }                                                        // /
    } // inner scope now stops here
}

It is not true that 'variable is now larger than 'reference, because 'reference is declared earlier still.

So this is confusing to me. It would make more sense if it read:

we can then formally say that for any variable that references another variable, 'variable must live longer than 'reference.

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.