GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - tokyorust/trm6-ch2-identifier-madness

BranchesTags
Open more actions menu

Latest commit

 

History

11 Commits
11 Commits

Folders and files

NameName
Last commit message
Last commit date
src
src
 
 
.gitignore
.gitignore
 
 
Cargo.lock
Cargo.lock
 
 
Cargo.toml
Cargo.toml
 
 
README.md
README.md
 
 

Repository files navigation

Challenge #2 - Identifier madness

For Tokyo Rust Meetup's mini-hackathon on 2016-06-23.

Setup

For this task, any Rust nightly should be fine.

The challenge

So you have a friend who likes to use UUIDs as identifiers. Another swears by plain numbers, claiming that u64 will surely be enough for everything. You don't feel like getting into a religious argument with them, so you decide to make your library work with both methods.

Stepping up the difficulty from challenge 1, you task is to make the provided Record API work with both String (representing UUIDs) and u64 (representing numeric identifiers).

Simply make cargo test pass without removing any tests and you're done! For convenience, cargo run already works and can be used for quick testing.

(Optional bonus challenge 1)

Make Record accept a &str as well, for convenience reasons. Hint: the solution from challenge 1 may not work so well this time!

(Optional bonus challenge 2)

There may be no identifier at all for new records that haven't been saved yet. We are currently unable to represent those at all. Make Record's id optional. Additionally, add an is_new(&self) -> bool method into Record and create a test for it.

(Optional bonus challenge 3)

Now we're able to create identifiers just fine. But what about when we want to use it? Imagine a situation where you have the following code:

fn find_record(id: Identifier) -> Option<Record> {
    let _query = format!("select * from records where id = {}", id);
    // Code to run the imaginary query here, irrelevant for this task.
    // Let's just return None and claim that we can't find anything.
    None
}

This won't compile. Think of a way to make it compile without adding too many lines inside the method itself. Note that the UUID should perhaps be quoted (preferably only in the context of the query), whereas Numeric doesn't need quoting at all.

About

No description, website, or topics provided.

Resources

Readme
Activity
Custom properties

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.