题叶. 工作前几年专注 React 单页面应用. 对 Rust, WebGPU 感兴趣. Calcit 脚本语言.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3 | |
connect(3, {sa_family=AF_UNIX, sun_path="/var/run/nscd/socket"}, 110) = 0 | |
sendto(3, "\2\0\0\0\r\0\0\0\6\0\0\0hosts\0", 18, MSG_NOSIGNAL, NULL, 0) = 18 | |
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP}], 1, 5000) = 1 ([{fd=3, revents=POLLIN|POLLHUP}]) | |
recvmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="hosts\0", iov_len=6}, {iov_base="\310O\3\0\0\0\0\0", iov_len=8}], msg_iovlen=2, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[4]}], msg_controllen=20, msg_flags=MSG_CMSG_CLOEXEC}, MSG_CMSG_CLOEXEC) = 14 | |
mmap(NULL, 217032, PROT_READ, MAP_SHARED, 4, 0) = 0x7fcecddc1000 | |
close(4) = 0 | |
close(3) = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 | |
00:00:00,100 --> 00:00:02,533 | |
嘿,朋友们,这里是Visionary 3D | |
2 | |
00:00:02,533 --> 00:00:03,700 | |
今天我们将 | |
3 | |
00:00:03,700 --> 00:00:06,766 |
以 Rust 语言为例, 深入介绍 Sum Type 对于程序简洁和可靠性带来的帮助. 跟 TypeScript 当中的写法做对比. 文章分成 3 个大的部分.
第一部分介绍什么是 Sum Type(特别是带参数的情况), 比如在 Rust 当中的有哪些语法, 详细展示一下. 然后展开介绍 Sum Type 在其他编程语言的使用历史和经验, 业界怎样一步步接受 Sum Type 的使用.
第二部分展示一下 TypeScript 当中模拟带参数的 sum type 的用法, 分析一下对比 Rust 当中写法的优势和劣势. 注意提供一个案例来读取数据. 分别基于 tagged union 写法, 跟 interface 写法, 来展示和对比.
第三部分基于 Rust 的 Sum Type 展示一个业务的场景, 配合 Pattern Matching 用一段较复杂的逻辑来展示实用性. 特别是写一个例子来展示出在代码变更时, 模式匹配配合类型, 在代码的可靠性上的优势. 展示一下 Rust 是如何帮你避免因为业务变更写出 Bug 的, 比如增加一个新的 Variant, 通过代码展示一下 Rust 编译器怎样提示出现的错误.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use image::{ImageBuffer, Rgb}; | |
use num_complex::Complex; | |
use std::f64::consts::PI; | |
const WIDTH: u32 = 512; | |
const HEIGHT: u32 = 255; | |
const MAX_ITERATIONS: u32 = 99; | |
fn main() { | |
let mut img = ImageBuffer::new(WIDTH, HEIGHT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM rust:1.80 | |
RUN wget -qO- https://github.com/trunk-rs/trunk/releases/download/v0.20.2/trunk-x86_64-unknown-linux-gnu.tar.gz | tar -xzf- | |
RUN rustup target add wasm32-unknown-unknown | |
RUN mv trunk /usr/local/bin/ | |
COPY config.toml /usr/local/cargo/config | |
RUN trunk --version | |
- JSX 当中表达式
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Eff { | |
run(Self) -> Unit | |
} | |
struct A { | |
a: Int | |
} derive (Debug) | |
fn A::run(self: A)-> Unit { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
execve("/home/chen/.cargo/bin/cr", ["cr", "-1"], 0x7fff39f9f308 /* 33 vars */) = 0 | |
brk(NULL) = 0x565054d1e000 | |
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd0f18ad000 | |
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) | |
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 | |
fstat(3, {st_mode=S_IFREG|0644, st_size=87867, ...}) = 0 | |
mmap(NULL, 87867, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd0f1897000 | |
close(3) = 0 | |
openat(AT_FDCWD, "/lib64/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3 | |
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 832) = 832 |
NewerOlder