Rust에서 LLVM Intrinsics 호출하기
Posted: November 28, 2015 Filed under: Code, Tokamak Project | Tags: llvm, rust, tokamak Leave a comment요즘에는 내가 보려는 목적으로 기록을 하는 블로깅이 대부분인 듯 하다. Rust는 LLVM으로 구현되어 있고 LLVM 의 Intrinsics를 함수에 매핑해서 호출할 수 있는 기능이 공식적으로 제공된다. 예제는 아래와 같다.
#![feature(link_llvm_intrinsics)] | |
extern { | |
#[link_name = “llvm.sqrt.f32”] | |
fn sqrt(x: f32) -> f32; | |
} | |
fn main(){ | |
unsafe { sqrt(32.0f32); } | |
} |
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’