A skeleton code for Iterator in Rust

For record, I wrote down the same code.

Consuming Iterator

pub struct TaskSet;
pub struct TaskSetIterator {
}
impl Iterator for TaskSetIterator {
type Item = Task;
fn next(&mut self) -> Option<Task> {
….
}
}
pub struct Task;
impl IntoIterator for TaskSet {
type Item = Task;
type IntoIter = TaskSetIterator;
fn into_iter(self) -> Self::IntoIter {
TaskSetIterator { … }
}
}

view raw
task.rs
hosted with ❤ by GitHub

Iterator that does not consume items

pub struct TaskSetRefIterator<'a>
{
….
}
impl<'a> Iterator for TaskSetRefIterator<'a> {
type Item = &'a Task;
fn next(&mut self) -> Option<&'a Task> {
None
}
}
impl<'a> IntoIterator for &'a TaskSet {
type Item = &'a Task;
type IntoIter = TaskSetRefIterator<'a>;
fn into_iter(self) -> Self::IntoIter {
TaskSetRefIterator { … }
}
}

view raw
task2.rs
hosted with ❤ by GitHub


Awesome documentation links for Rust

I wrote down the useful links that I have learned. I’ll continue to update it.

General

Abstraction

Ownership

Object Safety

FFI

Iterator

Pattern Matching

Error handling

biild.rs

Examples

Idiomatic Usages of Rust

API Design

Ownership

Network and I/O

Macro

MIO

Projects Worth Watching

Papers

Profiling

Updates

  • Oct 15, 2015 – Added The Little Book of Rust Macros.
  • Nov 3. 2015 – Add ‘Rust Design Pattern’ and ‘Exposing Rust struct to Python’

Git에서 GPG key로 signoff 하기

공헌자들 패치를 받아서 커밋할 때, 컨트리뷰터의 author를 유지하면서 또한 커미터가 직접 확인했다는 증명을 signoff 기능을 통해 할 수 가 있다. 그런데 signoff 가 단순하게 커밋로그에 남는 ‘메일 주소와 이름 뿐’인 태그일 뿐이라서 진짜 그 사람이 signoff를 했는지 증명하는 것이 어렵다는 문제가 있다. 다행히 git에서는 GPG key를 이용한 signoff 기능을 제공한다. 우선은 내가 볼 목적으로 그리고 동료들에게 설명할 목적으로 정리를 해본다.

GPG에 대한 사용법은 생략한다. 우선 자신의 Key id를 얻는다.

$ gpg –list-secret-keys | grep ^sec
sub 4096R/4CFE2390 2013-10-16 [expires: 2017-10-16]
# ^— your key id

view raw
list_gpg_key.sh
hosted with ❤ by GitHub

그리고 git config의 user.signingkey로 GPG key id를 설정한다. 각 repository 마다 설정하고 싶으면 –global 옵션을 빼면 지정 repository에만 (현재 디렉토리의 git repository) 지정할 수 있다.

# remove –global to use this key only on the current repository
$ git config –global user.signingkey 4CFE2390
# ^- replace with your key id

그리고 커밋을 한다. 아래 옵션이 많지만 GPG key로 사인을 위한 옵션은 -S 이다.

hyunsik@workstation:~/Code/tajo/tajo$ git commit -S -m "TAJO-1909: Eliminate remained explicit diamond expressions."</code>
You need a passphrase to unlock the secret key for
user: "Hyunsik Choi <hyunsik@apache.o….>"
4096-bit RSA key, ID 4CFE2390, created 2013-10-16 (main key ID AC3885B9)
[master 6bc9fbb] TAJO-1909: Eliminate remained explicit diamond expressions.
Author: Dongkyu Hwangbo <hwang….@gma……>;
Date: Thu Oct 8 15:02:58 2015 -0700
72 files changed, 150 insertions(+), 147 deletions(-)

view raw
commit_with_gpg_sign
hosted with ❤ by GitHub

GPG key-agent가 켜져 있다면 패스워드 직접 입력없이 자동으로 위에서 설정한 키로 사인과 함께 커밋이 된다. 그럼 확인해보자.

hyunsik@workstation:~/Code/tajo/tajo$ git log –show-signature
commit 6bc9fbb50fb8b45d3fd58d9f10f74fefe62106fe
gpg: Signature made Thu 08 Oct 2015 03:15:39 PM PDT using RSA key ID 4CFE2390
gpg: Good signature from "Hyunsik Choi <hyunsik@apach.o..>"
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: 9141 BD40 6A84 DBA1 F4BD 5F04 024C 922A AC38 85B9
Subkey fingerprint: 1BB1 D697 599C 74BD C917 2F89 FE68 DD32 4CFE 2390

view raw
show_signature.sh
hosted with ❤ by GitHub

‘not certified’라고 나올 수 가 있다. key가 로컬 머신에 등록되어 있지만 trust key로 설정되어 있지 않아서 그렇다고 한다 (자세히는 모름). 해결은 아래와 같이 --edit-key 옵션으로 한다.

hyunsik@workstation:~/Code/tajo/tajo$ gpg –edit-key 4CFE2390 trust
gpg (GnuPG) 1.4.18; Copyright (C) 2014 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Secret key is available.
pub 4096R/AC3885B9 created: 2013-10-16 expires: 2017-10-16 usage: SCEA
trust: unknown validity: unknown
sub 4096R/4CFE2390 created: 2013-10-16 expires: 2017-10-16 usage: SEA
[ unknown] (1). Hyunsik Choi <hyunsik@apach.o….>;
pub 4096R/AC3885B9 created: 2013-10-16 expires: 2017-10-16 usage: SCEA
trust: unknown validity: unknown
sub 4096R/4CFE2390 created: 2013-10-16 expires: 2017-10-16 usage: SEA
[ unknown] (1). Hyunsik Choi <hyunsik@apach.o….>;
Please decide how far you trust this user to correctly verify other users' keys
(by looking at passports, checking fingerprints from different sources, etc.)
1 = I don't know or won't say
2 = I do NOT trust
3 = I trust marginally
4 = I trust fully
5 = I trust ultimately
m = back to the main menu
Your decision? 5
Do you really want to set this key to ultimate trust? (y/N) y

view raw
edit-key.sh
hosted with ❤ by GitHub

그리고 다시 확인해보자.

hyunsik@workstation:~/Code/tajo/tajo$ git log –show-signature
commit 5d470bc6001bb4fe096d7a8d221e51c18c683899
gpg: Signature made Thu 08 Oct 2015 03:21:24 PM PDT using RSA key ID 4CFE2390
gpg: Good signature from "Hyunsik Choi "

Warning이 없어진 것을 알 수 있다.

See Also