Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
RustからX Window Systemを触る
Search
garasubo
January 27, 2020
710
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RustからX Window Systemを触る
garasubo
January 27, 2020
Transcript
8 slides
RustからX Window Systemを触る @garasubo
きっかけ Mozillaの新しいブラウザエンジンのServoのIssueに取り掛 かろうとした https://github.com/servo/servo/issues/24724 Servoの依存するライブラリに変更が必要なことがわかり、 x11を触ることに
X Window System (X11) Linuxのウィンドウシステムの1つ C言語用のインタフェースが提供されている RustもC言語インターフェースを呼び出しをサポート しているので、Rustでも使える
RustからX11ライブラリを触る バインディングのクレートが存在している https://crates.io/crates/x11-dl いくつか対応していないインターフェースもある
RustとC言語はデータ表現が違う 構造体にはrepr(C)をつける 文字列ではStringではなくCstring、CStrを使う 関数ポインタはOptionでラップする Rustでは関数ポインタは0(Null)にならないが、Cではなりえる
Optionは0になりなりえない型ではNoneを0とする最適化を行う
C言語の型はゆるい 例:XIMのPreedit Start Callback 型定義 typedef void (*XIMProc)(XIM,XPointer,XPointer); 現実 static
int preedit_start_callback( XIC xim, XPointer client_data, XPointer call_data){}
C言語にはライフタイムがない 一度参照から生ポインタに変換するとライフタイムや Mutabilityのチェックが消える C言語から渡されてくる生ポインタにもライフタイムがな い 例:C言語からくる文字列ポインタをCString::from_rawに 渡してしまう
Rust側にオーナーシップを渡してしまい、勝手にリソースを開放し てしまう CStrを使うのが正解
まとめ C言語とRustのデータ表現の差異から来る罠はたくさんある ただのC言語バインディングではRustの旨味が消えてしまう 適切にC言語ライブラリをラップして汚いところを隠蔽しま しょう X11直接触るよりはそれをラップしたwinitを使うと楽
https://github.com/rust-windowing/winit
More Decks by garasubo
See All by garasubo
Cancel Safetyとスレッドリーク
garasubo
1
860
RustでISUCONに勝つには
garasubo
1
860
Rustでの自作OSをやってきて
garasubo
0
1.3k
Armの仮想化支援機構を用いてハイパーバイザーを自作する
garasubo
3
8.3k
Rustで始める自作組込みOS
garasubo
1
3.7k
クラウド向けOS(?)Unikernelとは何か
garasubo
0
1.8k
論文紹介:KVM/ARM: The Design and Implementation of the Linux ARM Hypervisor
garasubo
0
700
Featured
See All Featured
A Modern Web Designer's Workflow
chriscoyier
699
190k
For a Future-Friendly Web
brad_frost
184
11k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.7k
Facilitating Awesome Meetings
lara
57
7.2k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.7k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
520
Navigating Weather and Climate Data
rabernat
0
590
The Cult of Friendly URLs
andyhume
79
7.1k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
350
How Software Deployment tools have changed in the past 20 years
geshan
3
35k
Ruling the World: When Life Gets Gamed
codingconduct
0
440