Skip to content

zongwu's blog

Tag: #源码

WriterT 相关源码分析

看完ReaderT源码,接着来分析WriterT的源码。

示例

先看一个超级简单的例子:

import Control.Monad
import Control.Monad.Trans.Writer

data LogEntry = LogEntry { msg :: String } deriving (Eq, Show)

calc :: Writer [LogEntry] Integer calc = do tell [LogEntry "Start"] let x = sum [1 .. 10000000] tell [LogEntry (show x)] tell [LogEntry "done"] return x

test = execWriter calc test2 = runWriter calc

test执行结果:

[LogEntry {msg = "Start"},LogEntry {msg = "50000005000000"},LogEntry {msg = "done"}]

Rust mio库源码情景分析

mio 是 Metal IO,Rust语言生态比较底层的I/O库,官网的介绍:

Mio is a lightweight I/O library for Rust with a focus on adding as little overhead as possible over the OS abstractions.

mio目前已经发布了v0.6.19版本,这次分析代码版本选择 master分支,commit id 14f37f283576040c8763f45de6c2b2bbcb82436d

我们从官方自带的example进行源码跟踪分析。