rust-lang / rust-lang/rfcs

only require Show for elements joined with connect

Open
#720 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T-libs
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

Issue by panzi
Saturday May 03, 2014 at 02:19 GMT

For earlier discussion, see https://github.com/rust-lang/rust/issues/13911

This issue was labelled with: in the Rust repository


In most high level languages it's easy to turn a list/array of things into a comma separated string. In Rust there is the connect method, but it requires the elements to implement the trait std::str::Str. I would like this method to require std::fmt::Show instead. Alternatively a join method with according semantics that requires std::fmt::Show would suffice.

Currently you have to write:

let xs = [1, 2, 3];
let str_xs: ~[~str] = xs.iter().map(|x| x.to_str()).collect();
println!("xs = {}", str_xs.connect(", "));

let mut ys = Vec::new();
ys.push(4);
ys.push(5);
ys.push(6);
let str_ys: Vec<~str> = ys.iter().map(|y| y.to_str()).collect();
println!("ys = {}", str_ys.connect(", "));

This is pretty horrible. This would be much nicer:

let xs = [1, 2, 3];
println!("xs = {}", xs.connect(", "));

let mut ys = Vec::new();
ys.push(4);
ys.push(5);
ys.push(6);
println!("ys = {}", ys.connect(", "));

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the earlier discussion in rust-lang/rust#13911 and the surrounding RFC context. Investigate the existing connect API and the Str and Show traits in the Rust repository; done means the preferred API change is clearly specified and accepted for implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.