Rust에서 LLVM Intrinsics 호출하기

요즘에는 내가 보려는 목적으로 기록을 하는 블로깅이 대부분인 듯 하다. 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); }
}

view raw

intrinsics.rs

hosted with ❤ by GitHub


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’