A skeleton code for Iterator in Rust
Posted: October 13, 2015 Filed under: Code | Tags: iterator, rust Leave a commentFor 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 { … } | |
} | |
} |
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 { … } | |
} | |
} |
Awesome documentation links for Rust
Posted: October 11, 2015 Filed under: Code, FOSS | Tags: rust Leave a commentI wrote down the useful links that I have learned. I’ll continue to update it.
General
- The Rust Programming Language
- Rust for C++ programmers
- The Advanced Rust Programming Language
- Rust for Rubyists
Abstraction
Ownership
- Lifetime in Rust Book
- Understanding Pointers, Ownership, and Lifetimes in Rust
- http://alvalea.gitbooks.io/rust-for-cpp/content/lifetimes.html
- Understanding Lifetime in Rust – Part I
- Understanding Lifetime in Rust – Part II
Object Safety
FFI
- Foreign Function Interface – Rust Book
- C types in Rust
- Rust FFI C string handling
- How do I get a *mut c_char from a Str?
- Rust Once, Run Everywhere
- FFI in Rust – writing bindings for libcpuid
- 24 days of Rust – calling Rust from other languages
- A Pythonist getting Rusty these days… Part 1, Part 2
- Exposing Rust struct to Python
Iterator
- Effectively Using Iterators In Rust
- A Journey into Iterators
- How can I zip more than two iterators?
- Correct way to return an Iterator?
- Itertools (very useful iterator helper utility)
Pattern Matching
Error handling
biild.rs
Examples
Idiomatic Usages of Rust
- Virtual Structs Part 1: Where Rust’s Enum Shines
- Modeling Graphs in Rust Using Vector Indices
- Rust Design Patterns
API Design
- String vs &str in Rust functions
- Creating a Rust function that accepts String or &str
- Creating a Rust function that returns a &str or String
- Learning Rust With Entirely Too Many Linked Lists
- Rust’s Built-in Traits, the When, How & Why
Ownership
Network and I/O
Macro
MIO
- API Documentation
- mio book
- Getting Acquainted with MIO
- mio source code
- Creating A Multi-echo Server using Rust and mio
- Accumulating echo server using Rust’s mio
- My Basic Understanding of mio and Asynchronous IO
Projects Worth Watching
- Awesome Rust
- Rust in Detail
- Asynchronous IO in Rust
- Building an iOS App in Rust, Part 1: Getting Started with Rust
- Creating A Multi-echo Server using Rust and mio
- Index 1,600,000,000 Keys with Automata and Rust
Papers
Profiling
- Blog: Profiling Rust applications (comments)
- Rust Performance: A story featuring perf and flamegraph on Linux
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 하기
Posted: October 9, 2015 Filed under: Code, FOSS | Tags: git, gpg Leave a comment공헌자들 패치를 받아서 커밋할 때, 컨트리뷰터의 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 |
그리고 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(-) |
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 |
‘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 |
그리고 다시 확인해보자.
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이 없어진 것을 알 수 있다.