Skip to content

Instantly share code, notes, and snippets.

View crlf0710's full-sized avatar
🙂
Smiling

Charles Lew crlf0710

🙂
Smiling
  • Beijing
View GitHub Profile
#![allow(missing_docs)] // FIXME
pub trait Atom<'a> {
fn as_str(&self) -> &str;
fn is_whitespace(&self) -> bool;
fn is_comment_content(&self) -> bool;
fn can_prepend_lrm(&self) -> bool;
fn prepend_lrm(&self);
fn prepend_fsi(&self);
fn remove_lrm_and_rlm(&self);

Rust 之所以为 Rust —— Rust进阶教程,前言

有段时间没有写关于Rust的东西了,在这段时间里,Rust发布了2018的大版本,增加了一些之前答应的功能,生态上有了一些进步。在国内国外,比起之前一段时间,听说过Rust的人变多了,关注Rust的人变多了,实际在写Rust的人也变多了。PYPL排行榜上,Rust目前已经升到了18位。超过前面17位的Visual Basic,甚至赶上第16位的Scala,我觉得也是很有希望的,只是可能再需要一点时间。整体来说,大概还算是欣欣向荣的。至于短时间内成为爆款什么的,个人觉得倒是可能性不大,不过万一火了呢,毕竟前面有Clojure、Scala的先例嘛。

这次打算写一点进阶的东西。如果是入门的话,其实现在Rust入门教程已经有很多了。官方的教程《The Rust Programming Language》已经出了实体书,还有Rust By Examples也在一直更新。Ralf Jung聚聚的《Rust 101》我也蛮喜欢的,还有Niko Matsakis聚聚之前录的《Into Rust》五集视频教程。还有很多我只听说过但是没有深入了解的,比如NRC聚聚写的Rust for C-Plus-Plus Programmers, Youtube上的jonhoo录的视频教程系列,还有O'Reilly出了一本实体书Programming Rust。国内这边,范老师和张老师先后出了两本Rust入门教程的实体书,很抱歉我还都没拜读过,不过听说口碑也都还可以。哦对了,可能很少有人知道,JetBrains已经把Rust官方的Rustlings做进了它的教育包里,也就是交互式教程。感兴趣的也可以玩玩看。

不过貌似网上关于进阶的东西貌似不是很多。Rust 并不是一门简单的语言,实际上它的技术细节是相当多的。初学者们在入门阶段读的东西,一般都是入门教程作者精心挑选之后拿给你们的东西。一次一个主题,能够在不把读者吓跑的同时把读者写程序解决实际问题时可能用到的主题内容细致的传达给读者。即使这样,内容就已经很多了…… 读者很少会有余力去想,有没有Rust本身的设计里有,但是书籍作者没有传达的内容呢?实际上,不但有,而且还很多很重要:)。

所以就有了这个系列,我会尝试跳过入门书籍的职责,直接讨论Rust的世

@crlf0710
crlf0710 / graphics2d.rs
Created May 21, 2019 07:23
Graphics2D.rs draft
// Written by CrLF0710<crlf0710@gmail.com>
// Licensed with MIT OR Apache-2.0
trait GraphicsSolution {
}
trait GraphicsContextBuilder<T: GraphicsSolution> {
type ImmediateContext: GraphicsContext;
type RetainedRasterContext: GraphicsContext;
@crlf0710
crlf0710 / a.gnux32.ll
Created April 3, 2019 16:59
Rust unsized_locals codegen issue on gnu x32.
; ModuleID = 'a.3a1fbbbh-cgu.0'
source_filename = "a.3a1fbbbh-cgu.0"
target datalayout = "e-m:e-p:32:32-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnux32"
@vtable.0 = private unnamed_addr constant { void (i32*)*, i32, i32, i32 (i32*)* } { void (i32*)* @_ZN4core3ptr18real_drop_in_place17hbeb95fb5bcd2320eE, i32 4, i32 4, i32 (i32*)* @"_ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17heb625444409ca88cE" }, align 4
; <usize as core::default::Default>::default
; Function Attrs: inlinehint nounwind
define internal i32 @"_ZN48_$LT$usize$u20$as$u20$core..default..Default$GT$7default17h194d800cf4bc33ceE"() unnamed_addr #0 {
// This script works when you open the CodeCharts.pdf from Unicode 9.0.0 standard in Acrobat/Reader.
var execGotoUnicodePageDlg = app.trustedFunction (function () {
if (this.numPages != 2489) {
app.alert("This is NOT Unicode 9.0 CodeCharts.pdf");
return;
}
var doc = this;
var dlg = {
description: { name: "Goto Unicode",