burntsushi
30 articles
将正则表达式引擎内部作为库
Translated
AI Summary
eng
[AI 摘要] 本文讨论了重写Rust正则表达式库的动机、解决方案,并介绍了将引擎内部暴露为API的新库regex-automata。
View content
<p>过去几年,我对<a href="https://github.com/rust-lang/regex/">Rust的<code>regex</code> crate</a>进行了重写,旨在改善内部组件的组合性,使其在保证正确性的同时更易于添加优化。在此重写过程中,我创建了一个新crate:<a href="https://github.com/rust-lang/regex/tree/master/regex-automata"><code>regex-automata</code></a>,它将<code>regex</code> crate的大量内部实现作为独立API提供给他人使用。据我所知,这是首个以独立版本库形式,如此深入地暴露其内部机制的正则表达式库。</p>
<p>这篇博客文章讨论了导致此次重写的问题、重写如何解决了这些问题,并引导读者了解<code>regex-automata</code>的API。</p>
<p><strong>目标受众</strong>:Rust程序员以及任何对某个特定有限自动机正则表达式引擎实现方式感兴趣的人。假定具备正则表达式的先验知识。</p>
Show original
<p>Over the last several years, I’ve rewritten <a href="https://github.com/rust-lang/regex/">Rust’s <code>regex</code>
crate</a> to enable better internal composition, and to make it
easier to add optimizations while maintaining correctness. In the course of
this rewrite I created a new crate, <a href="https://github.com/rust-lang/regex/tree/master/regex-automata"><code>regex-automata</code></a>, which exposes much
of the <code>regex</code> crate internals as their own APIs for others to use. To my
knowledge, this is the first regex library to expose its internals to the
degree done in <code>regex-automata</code> as a separately versioned library.</p>
<p>This blog post discusses the problems that led to the rewrite, how the rewrite
solved them and a guided tour of <code>regex-automata</code>’s API.</p>
<p><strong>Target audience</strong>: Rust programmers and anyone with an interest in how one
particular finite automata regex engine is implemented. Prior experience wi…
面向 Rust 的字节字符串库
Translated
AI Summary
eng
[AI 摘要] 本文介绍了新发布的 Rust 字节字符串库 bstr 1.0,阐述其设计理念、API 及使用场景。
View content
<p><a href="https://docs.rs/bstr/1.*"><code>bstr</code></a> 是一个面向 Rust 的字节字符串库,其 <a href="https://github.com/BurntSushi/bstr/releases/tag/1.0.0">1.0 版本刚刚发布</a>!它为任意字节序列提供了面向字符串的操作,但当这些字节是 UTF-8 编码时尤为实用。换句话说,它提供了一个按<em>约定</em>为 UTF-8 编码的字符串类型,而 Rust 内置的字符串类型则<em>保证</em>为 UTF-8 编码。</p>
<p>本文将简要描述其 API,深入探讨创建 <code>bstr</code> 的动机,展示一些使用 <code>bstr</code> 的简短示例程序,并以几点思考作为结语。</p>
<p><strong>目标读者</strong>:具备一定 UTF-8 背景知识的 Rust 程序员。</p>
Show original
<p><a href="https://docs.rs/bstr/1.*"><code>bstr</code></a> is a byte string library for Rust and <a href="https://github.com/BurntSushi/bstr/releases/tag/1.0.0">its 1.0 version has
just been released</a>! It provides string oriented operations on
arbitrary sequences of bytes, but is most useful when those bytes are UTF-8. In
other words, it provides a string type that is UTF-8 by <em>convention</em>, where as
Rust’s built-in string types are <em>guaranteed</em> to be UTF-8.</p>
<p>This blog will briefly describe the API, do a deep dive on the motivation for
creating <code>bstr</code>, show some short example programs using <code>bstr</code> and conclude
with a few thoughts.</p>
<p><strong>Target audience</strong>: Rust programmers with some background knowledge of UTF-8.</p>
在 Rust 中使用 unwrap() 是可以的
Translated
AI Summary
eng
[AI 摘要] 这篇文章解释了在 Rust 中在特定情况下(如测试代码)使用 unwrap() 是可接受的,并解决了关于其使用的常见误解。
View content
<p>在 Rust 1.0 发布的前一天,我发布了一篇<a href="https://blog.burntsushi.net/rust-error-handling/">涵盖错误处理基础的博客文章</a>。文章中间有一个特别重要但篇幅较小的部分,标题为“<a href="https://blog.burntsushi.net/rust-error-handling/#a-brief-interlude-unwrapping-isnt-evil">unwrap 并非邪恶</a>”。该部分简要描述了,广泛来说,如果在测试/示例代码中使用 <code>unwrap()</code>,或者当 panic 表示一个 bug 时,是可以的。</p>
<p>我今天通常仍然持有这种信念。这种信念在 Rust 的标准库和许多核心生态系统 crate 中得到了实践。(而且这种实践早于我的博客文章。)然而,关于何时可以和不可以使用 <code>unwrap()</code> 似乎仍然存在广泛的混淆。这篇文章将更详细地讨论这一点,并具体回应我所看到的一些观点。</p>
<p>这篇博客文章在某种程度上写得像一个常见问题解答,但它是有意按顺序阅读的。每个问题都建立在前一个基础上。</p>
<p><strong>目标受众</strong>:主要是 Rust 程序员,但我希望提供足够的上下文,使这里倡导的原则适用于任何程序员。尽管对于具有不同错误处理机制(如异常)的语言,可能很难直接映射。</p>
Show original
<p>One day before Rust 1.0 was released, I published a
<a href="https://blog.burntsushi.net/rust-error-handling/">blog post covering the fundamentals of error handling</a>.
A particularly important but small section buried in the middle of the article
is named “<a href="https://blog.burntsushi.net/rust-error-handling/#a-brief-interlude-unwrapping-isnt-evil">unwrapping isn’t evil</a>”. That section briefly
described that, broadly speaking, using <code>unwrap()</code> is okay if it’s in
test/example code or when panicking indicates a bug.</p>
<p>I generally still hold that belief today. That belief is put into practice in
Rust’s standard library and in many core ecosystem crates. (And that practice
predates my blog post.) Yet, there still seems to be widespread confusion about
when it is and isn’t okay to use <code>unwrap()</code>. This post will talk about that
in more detail and respond specifically to a number of positions I’ve seen
expressed.…
System76 Darter Pro 上的 Archlinux
Translated
AI Summary
eng
[AI 摘要] 本文介绍了在配备 Coreboot 的 System76 Darter Pro 上安装和配置 Arch Linux 的体验,面向寻找 Linux 兼容笔记本的用户。
View content
<p>这是一篇简短的博文,回顾我在配备 Coreboot 的 System76 Darter Pro(型号:darp6)上运行 Archlinux 的配置,以及我对这款笔记本电脑的一些总体看法。这是我自 <a href="https://blog.burntsushi.net/lenovo-thinkpad-t430-archlinux">2012 年 7 月购买 ThinkPad T430</a> 以来的首次笔记本电脑升级</p>
<p>目标读者:正在寻找兼容 Linux 笔记本电脑的 Archlinux 用户。</p>
Show original
<p>This is a quick post reviewing my Archlinux setup on a System76 Darter Pro
(model: darp6) with Coreboot, along with some thoughts about the laptop in
general. This is my first laptop upgrade since I
<a href="https://blog.burntsushi.net/lenovo-thinkpad-t430-archlinux">purchased a ThinkPad T430 in July 2012</a></p>
<p>Target audience: Archlinux users looking for a compatible Linux laptop.</p>
我的FOSS故事
Translated
AI Summary
eng
[AI 摘要] 这是一篇关于作者个人参与自由开源软件(FOSS)经历的反思文章,旨在分享故事并促进社区内的同理心。
View content
<p>我想暂时跳出自己专注于技术内容的惯例,分享一点我与自由开源软件(FOSS)的个人关系。虽然每个人都不同,但我希望通过分享我的观点,帮助建立理解、同理心和信任。</p>
<p>这并非旨在直接回应任何其他维护者的行为。也不应被解读为对FOSS中某人理想行为的规范。这更多是一次个人反思,希望他人能用它来思考自己与FOSS的关系。成为优秀的FOSS维护者并无唯一正确的路径。我们都有自己的应对机制。</p>
<p>这同样绝非求助的呼吁。这是关于理解。这不是恳求改变FOSS的经济模式。这不是头脑风暴改善我的心理健康的方法。这不是为了引入更多维护者。这是分享我的故事,并试图增进FOSS社区成员之间的同理心。</p>
<p><strong>目标受众</strong>:任何参与FOSS的人。
Show original
<p>I’d like to break from my normal tradition of focusing almost strictly on
technical content and share a bit of my own personal relationship with Free
and Open Source Software (FOSS). While everyone is different, my hope is that
sharing my perspective will help build understanding, empathy and trust.</p>
<p>This is not meant to be a direct response to the behavior of any other
maintainer. Nor should it be read as a prescription on the ideal behavior of
someone in FOSS. This is meant more as a personal reflection with the hope that
others will use it to reflect on their own relationship with FOSS. There is no
one true path to being a good FOSS maintainer. We all have our own coping
mechanisms.</p>
<p>This is also emphatically not meant as a call for help. This is about
understanding. This is not about a plea to change the economics of FOSS. This
is not about brainstorming ways to improve my mental health. This is not about
bringing on more maintainers. It’s about sharing m…
Rust 与 CSV 解析
Translated
AI Summary
eng
[AI 摘要] 一篇面向 Rust 初学者的教程,介绍如何使用 csv 1.0 库读写 CSV 数据。
View content
<p>随着 <code>csv 1.0</code> 的发布,正是撰写一篇关于如何在 Rust 中读写 CSV 数据的教程的好时机。本教程面向 Rust 初学者,因此包含大量示例,并花费一些篇幅介绍基本概念。经验丰富的 Rust 程序员可能会觉得其中部分内容有用,但快速浏览一下可能更合适。</p>
<p>关于 Rust 的入门介绍,请参阅<a href="https://doc.rust-lang.org/book/second-edition/">官方书籍</a>。如果你还没有编写过任何 Rust 代码,但在其他语言中编写过代码,那么本教程可能在你无需先阅读官方书籍的情况下也能理解。</p>
<p>CSV 库<a href="https://github.com/BurntSushi/rust-csv">可在 Github 上获取</a>,并有<a href="https://docs.rs/csv">详尽的 API 文档</a>。</p>
<p>最后,这篇博客文章的一个版本已作为<a href="https://docs.rs/csv/1.0.0/csv/tutorial/index.html">教程</a>包含在 API 文档中,并且随着时间的推移,它更有可能得到更新。</p>
<p><strong>目标读者</strong>:Rust 初学者。</p>
Show original
<p>With <code>csv 1.0</code> just released, the time is ripe for a tutorial on how to read
and write CSV data in Rust. This tutorial is targeted toward beginning Rust
programmers, and is therefore full of examples and spends some time on basic
concepts. Experienced Rust programmers may find parts of this useful, but would
probably be happier with a quick skim.</p>
<p>For an introduction to Rust, please see the
<a href="https://doc.rust-lang.org/book/second-edition/">official book</a>.
If you haven’t written any Rust code yet but have written code in another
language, then this tutorial might be accessible to you without needing to read
the book first.</p>
<p>The CSV library is
<a href="https://github.com/BurntSushi/rust-csv">available on Github</a>
and has
<a href="https://docs.rs/csv">comprehensive API documentation</a>.</p>
<p>Finally, a version of this blog post is included as a
<a href="https://docs.rs/csv/1.0.0/csv/tutorial/index.html">tutorial</a>
in the API documentation, …
ripgrep 比 {grep, ag, git grep, ucg, pt, sift} 更快
Translated
AI Summary
eng
[AI 摘要] 本文通过对25个基准测试的深入分析,论证了命令行工具ripgrep在性能和正确性上优于其他流行代码搜索工具。
View content
<p>在这篇文章中,我将介绍一个新的命令行搜索工具
<a href="https://github.com/BurntSushi/ripgrep"><code>ripgrep</code></a>,它结合了
<a href="https://github.com/ggreer/the_silver_searcher">The Silver Searcher</a>
(一个 <a href="http://beyondgrep.com/"><code>ack</code></a> 克隆版)的易用性与 GNU grep 的原始性能。<code>ripgrep</code> 速度快、跨平台(提供 Linux、Mac 和 Windows 的二进制文件),并使用 <a href="https://www.rust-lang.org">Rust</a> 编写。</p>
<p><code>ripgrep</code> 可在 <a href="https://github.com/BurntSushi/ripgrep">Github</a> 上获取。</p>
<p>我们将尝试做不可能的事:对几个流行的代码搜索工具进行公平的基准比较。具体来说,我们将深入探讨一系列 25 个基准测试,以证实以下论点:</p>
<ul>
<li>无论是搜索单个文件还是海量文件目录,其他工具在性能或正确性上都没有明显优于 <code>ripgrep</code>。</li>
<li><code>ripgrep</code> 是唯一支持 Unicode 且不会为此付出高昂代价的工具。</li>
<li>如果使用内存映射,同时搜索多个文件的工具通常<em>更慢</em>,而不是更快。</li>
</ul>
<p>作为一个在业余时间用 Rust 研究文本搜索已有 2.5 年,并且是 <code>ripgrep</code> 和 <a href="https://github.com/rust-lang-nursery/regex">底层正则表达式引擎</a> 的作者,我将借此机会深入剖析每种代码搜索工具的性能。每个基准测试都会被仔细审查!</p>
<p><strong>目标受众</strong>:熟悉 Unicode、编程并有一些命令行使用经验的读者。</p>
<p><strong>注意</strong>:我收…
Show original
<p>In this article I will introduce a new command line search tool,
<a href="https://github.com/BurntSushi/ripgrep"><code>ripgrep</code></a>,
that combines the usability of
<a href="https://github.com/ggreer/the_silver_searcher">The Silver Searcher</a>
(an <a href="http://beyondgrep.com/"><code>ack</code></a> clone) with the
raw performance of GNU grep. <code>ripgrep</code> is fast, cross platform (with binaries
available for Linux, Mac and Windows) and written in
<a href="https://www.rust-lang.org">Rust</a>.</p>
<p><code>ripgrep</code> is available on
<a href="https://github.com/BurntSushi/ripgrep">Github</a>.</p>
<p>We will attempt to do the impossible: a fair benchmark comparison between
several popular code search tools. Specifically, we will dive into a series of
25 benchmarks that substantiate the following claims:</p>
<ul>
<li>For both searching single files <em>and</em> huge directories of files, no other
tool obviously stands above <code>ripgrep</code> in either performance or…
使用自动机与Rust索引16亿个键
Translated
AI Summary
eng
[AI 摘要] 本文介绍如何使用有限状态机作为高效数据结构,通过Rust的fst工具实现大规模字符串索引与快速搜索。
View content
<p>事实证明,有限状态机不仅用于表达计算。它还可用于紧凑地表示字符串的有序集合或映射,从而实现极速搜索。</p>
<p>本文将介绍如何将有限状态机作为<em>数据结构</em>来表示有序集合与映射,包括一个用Rust编写的实现——<a href="https://github.com/BurntSushi/fst"><code>fst</code> crate</a>。它提供了<a href="https://burntsushi.net/rustdoc/fst/">完整的API文档</a>。我还将演示如何使用简单的命令行工具构建这些结构。最后,将通过几个实验展示如何索引来自<a href="http://blog.commoncrawl.org/2015/08/july-2015-crawl-archive-available/">2015年7月Common Crawl归档</a>的超过16亿条URL(134GB数据)。</p>
<p>本文所述的技术也是<a href="http://blog.mikemccandless.com/2010/12/using-finite-state-transducers-in.html">Lucene构建其倒排索引部分</a>所采用的方法。</p>
<p>在此过程中,我们将探讨内存映射、基于正则表达式的自动机交集、基于Levenshtein距离的模糊搜索以及流式集合操作。</p>
<p><strong>目标读者</strong>:具备编程和基础数据结构知识,无需自动机理论或Rust经验。</p>
Show original
<p>It turns out that finite state machines are useful for things other than
expressing computation. Finite state machines can also be used to compactly
represent ordered sets or maps of strings that can be searched very quickly.</p>
<p>In this article, I will teach you about finite state machines as a <em>data
structure</em> for representing ordered sets and maps. This includes introducing
an implementation written in Rust called the
<a href="https://github.com/BurntSushi/fst"><code>fst</code> crate</a>.
It comes with
<a href="https://burntsushi.net/rustdoc/fst/">complete API documentation</a>.
I will also show you how to build them using a simple command line tool.
Finally, I will discuss a few experiments culminating in indexing over
1,600,000,000 URLs (134 GB) from the
<a href="http://blog.commoncrawl.org/2015/08/july-2015-crawl-archive-available/">July 2015 Common Crawl Archive</a>.</p>
<p>The technique presented in this article is also how
<a href="http://blog.mikemccandless.com/2…
Rust 中的错误处理
Translated
AI Summary
eng
[AI 摘要] 本文面向 Rust 新手,全面介绍了 Rust 中基于返回值的错误处理方法,旨在帮助读者掌握标准库提供的简洁高效处理方式。
View content
<p>像大多数编程语言一样,Rust 鼓励程序员以特定的方式处理错误。一般来说,错误处理分为两大类:异常和返回值。Rust 选择了返回值。</p>
<p>在本文中,我打算全面介绍如何在 Rust 中处理错误。更重要的是,我将尝试逐步引入错误处理,以便您能扎实掌握所有内容如何协同运作。</p>
<p>如果以简单直接的方式编写,Rust 中的错误处理可能会显得冗长且令人烦恼。本文将探讨这些难点,并演示如何使用标准库使错误处理变得简洁且符合人体工程学。</p>
<p><strong>目标读者</strong>:那些刚接触 Rust 且尚不了解其错误处理惯用法的 Rust 新手。对 Rust 有一定熟悉程度会有所帮助。(本文大量使用了一些标准 trait 以及对闭包和宏的简单应用。)</p>
<p><strong>更新(2018/04/14)</strong>:示例已转换为使用 <code>?</code>,并添加了一些文本以提供此变更的历史背景。</p>
<p><strong>更新(2020/01/03)</strong>:移除了推荐使用
<a href="https://crates.io/crates/failure"><code>failure</code></a> 的内容,改为推荐使用
<a href="https://crates.io/crates/anyhow"><code>Box<Error + Send + Sync></code></a> 或
<a href="https://crates.io/crates/anyhow"><code>anyhow</code></a>。</p>
Show original
<p>Like most programming languages, Rust encourages the programmer to handle
errors in a particular way. Generally speaking, error handling is divided into
two broad categories: exceptions and return values. Rust opts for return
values.</p>
<p>In this article, I intend to provide a comprehensive treatment of how to deal
with errors in Rust. More than that, I will attempt to introduce error handling
one piece at a time so that you’ll come away with a solid working knowledge of
how everything fits together.</p>
<p>When done naively, error handling in Rust can be verbose and annoying. This
article will explore those stumbling blocks and demonstrate how to use the
standard library to make error handling concise and ergonomic.</p>
<p><strong>Target audience</strong>: Those new to Rust that don’t know its error handling
idioms yet. Some familiarity with Rust is helpful. (This article makes heavy
use of some standard traits and some very light use of closures and macros.)</p>
<p><…
Rust的语法扩展与正则表达式
Translated
AI Summary
eng
[AI 摘要] 本文介绍如何在Rust中通过语法扩展实现正则表达式编译为原生代码,并确保其与运行时编译的正则表达式API保持一致。
View content
<p><strong>警告:</strong> <!-- raw HTML omitted -->2018-04-12<!-- raw HTML omitted -->:本文的代码示例已不再提供。这倒也好,因为它们都依赖于一个已多年不存在的、不稳定的内部编译器接口。</p>
<p>几周前,我着手为<a href="http://www.rust-lang.org/">Rust</a>发行版添加正则表达式支持,其实现与功能集在很大程度上受到了<a href="http://swtch.com/~rsc/regexp/">Russ Cox的RE2</a>启发。它最近已被加入<a href="http://static.rust-lang.org/doc/master/regex/index.html">Rust发行版</a>。</p>
<p>这个正则表达式crate包含一个语法扩展,它能在Rust程序编译时,将正则表达式编译为原生的Rust代码。这可以被视为“提前”编译,或类似于<a href="http://en.wikipedia.org/wiki/Compile_time_function_execution">编译时函数执行</a>。这些特殊的原生编译正则表达式,与在运行时编译的正则表达式拥有*完全相同*的API。</p>
<p>本文将概述我的实现策略——包括如何编写Rust语法扩展的代码示例——并描述我如何实现编译时正则表达式与运行时正则表达式之间完全一致的API。</p>
Show original
<p><strong>WARNING:</strong> <!-- raw HTML omitted -->2018-04-12<!-- raw HTML omitted -->: The code snippets for this post are no longer
available. This is just as well anyway, since they all depended on an unstable
internal compiler interface, which hasn’t existed for years.</p>
<p>A few weeks ago, I set out to add regular expressions to the
<a href="http://www.rust-lang.org/">Rust</a>
distribution with an implementation and feature set heavily inspired by
<a href="http://swtch.com/~rsc/regexp/">Russ Cox’s RE2</a>.
It was just recently added to the
<a href="http://static.rust-lang.org/doc/master/regex/index.html">Rust distribution</a>.</p>
<p>This regex crate includes a syntax extension that compiles a regular expression
to native Rust code <em>when a Rust program is compiled</em>. This can be thought of
as “ahead of time” compilation or
something similar to <a href="http://en.wikipedia.org/wiki/Compile_time_function_execution">compile time function
execution</…
在Go中编写类型参数化函数
Translated
AI Summary
eng
[AI 摘要] 介绍一个Go工具包,用于编写能在运行时保持类型安全的类型参数化函数。
View content
<p>Go中唯一能在编译期保证类型安全的方法是结构化子类型(structural subtyping),而本文并不会改变这一点。相反,我将介绍一个名为<code>ty</code>的工具包,它提供了在Go中编写类型参数化函数的工具,这些函数能在<strong>运行时</strong>保持类型安全,同时也便于调用者使用。</p>
Show original
<p>Go’s only method of compile time safe polymorphism is structural subtyping, and
this article will do nothing to change that. Instead, I’m going to present a
package <code>ty</code> with facilities to write type parametric functions in Go that
maintain <strong>run time</strong> type safety, while also being convenient for the
caller to use.</p>
介绍NFLGame:以编程方式访问实时NFL比赛数据
Translated
AI Summary
eng
[AI 摘要] 文章介绍了一个旨在改善NFL数据获取方式的新库NFLGame。
View content
<p>作为一名程序员兼梦幻橄榄球爱好者,我对获取机器可读格式数据所必须采用的方式感到尴尬。
这种开源软件的缺乏,让社区受困于低标准的工具,最重要的是,它阻碍了利用易得的统计数据去实现一些真正酷炫且有趣的设想。
许多工具要么过时,要么损坏;即使能用,也往往是闭源的,且常常收费。</p>
<p>昨天,我开始着手开发一个新的库包,希望能开始改善这一可悲的现状。</p>
Show original
<p>As a programmer and a fantasy football addict, I am embarassed by the means
through which we must expend ourselves to get data in a machine readable form.
This lack of open source software cripples the community with sub-standard
tools, and most importantly, detracts from some really cool and fun things that
could be done with easily available statistics. Many tools are either out-dated
or broken, or if they work, they are closed source and often cost money.</p>
<p>Yesterday I started work on a new library package that I hope will start to
improve this sorry state of affairs.</p>
在联想Thinkpad T430上运行Archlinux
Translated
AI Summary
eng
[AI 摘要] 这是一篇关于在ThinkPad T430上安装和配置Archlinux的个人经验记录。
View content
<p>总之,Archlinux运行得非常好。以下是在安装、配置、调优和使用Archlinux于联想Thinkpad T430过程中记录的要点概述。</p>
Show original
<p>In sum, Archlinux is working beautifully. What follows is a rough run down of
my notes while installing, configuring, tuning and using Archlinux on the
Lenovo Thinkpad T430.</p>
守护进程化Go程序(附BSD风格rc.d示例)
Translated
AI Summary
eng
[AI 摘要] 文章介绍了Go语言因多线程特性难以传统守护进程化,建议使用nohup后台运行来解决。
View content
<p>Go语言天生具有多线程特性。这使得通过fork方式守护进程化Go程序的传统方法变得有些困难。</p>
<p>为了解决这个问题,您可以尝试一种简单的方法:将Go程序放到后台运行,并指示其<a href="http://en.wikipedia.org/wiki/Nohup">忽略HUP信号</a>:</p>
Show original
<p>Go, by its very nature, is multithreaded. This makes a traditional approach of
daemonizing Go programs by forking a bit difficult.</p>
<p>To get around this, you could try something as simple as backgrounding your Go
program and instructing it to <a href="http://en.wikipedia.org/wiki/Nohup">ignore the HUP
signal</a>:</p>
为X Go绑定添加线程安全性
Translated
AI Summary
eng
[AI 摘要] 本文讨论X Go绑定缺乏线程安全性的现状及其并行请求可能带来的问题。
View content
<p><a href="http://code.google.com/p/x-go-binding/">X Go绑定 (XGB)</a>是一个底层库,它提供了与运行中的X服务器交互的API。人们只能通过网络连接发送数据来与X服务器通信;协议请求、回复和错误需要精确构造到每一个字节。Xlib正是这样做的,甚至更多。结果,Xlib变得庞大且难以维护。</p>
<p>近年来,<a href="http://xcb.freedesktop.org/">XCB项目</a>使情况变得更为有序,它使用Python从描述X客户端协议的<a href="http://cgit.freedesktop.org/xcb/proto/tree/src">XML文件</a>生成C代码。虽然<a href="http://cgit.freedesktop.org/xcb/libxcb/tree/src/c_client.py">用于生成该代码的Python脚本</a>本身并不简单,但它通常优于另一种选择:随着大量扩展的存在而不断更新X核心协议。(XCB还有其他好处,例如更简单的异步性,但这超出了本文的范围。)</p>
<p>XGB沿用了类似的思路;<a href="http://code.google.com/r/jamslam-x-go-binding/source/browse/xgb/go_client.py">使用Python生成Go代码</a>来提供与X协议交互的API。与其姊妹项目XCB不同,它并非线程安全的。具体来说,如果并行发出X请求,最好的情况是请求或回复被搅乱,最坏的情况是X服务器崩溃。当需要将图像发送到X服务器进行屏幕绘制时,并行请求会特别有用;在此期间可以进行其他有用的工作。</p>
Show original
<p>The <a href="http://code.google.com/p/x-go-binding/">X Go Binding (XGB)</a> is a low level
library that provides an API to interact with running X servers. One can only
communicate with an X server by sending data over a network connection;
protocol requests, replies and errors need to be perfectly constructed down to
the last byte. Xlib did precisely this, and then some. As a result, Xlib became
huge and difficult to maintain.</p>
<p>In recent years, the <a href="http://xcb.freedesktop.org/">XCB project</a> made things a
bit more civilized by generating C code from <a href="http://cgit.freedesktop.org/xcb/proto/tree/src">XML
files</a> describing the X client
protocol using Python. While <a href="http://cgit.freedesktop.org/xcb/libxcb/tree/src/c_client.py">the Python to generate said
code</a> is no walk
in the park, it is typically preferred to the alternative: keeping the X core
protocol up to date along with any number of extensions that exist as well.
(There are other benefits to…
脑炎
Translated
AI Summary
eng
[AI 摘要] 作者分享了自己被诊断为抗NMDA受体脑炎的经历,并面向依赖其工作的读者进行说明。
View content
<p>我最近被诊断为<a href="https://en.wikipedia.org/wiki/Anti-NMDA_receptor_encephalitis">抗NMDA受体脑炎</a>。这是一种自身免疫性疾病,患者体内的抗体本应有益,但<a href="https://en.wikipedia.org/wiki/Anti-NMDA_receptor_encephalitis#Pathophysiology">却开始异常运作</a>,导致大脑炎症。这篇短文将简述我的一些经历和预后情况。</p>
<p><strong>目标读者</strong>:所有依赖我的工作来开展自身项目的人士。</p>
Show original
<p>I was recently diagnosed with <a href="https://en.wikipedia.org/wiki/Anti-NMDA_receptor_encephalitis">anti-NMDA receptor encephalitis</a>. It is
an autoimmune disorder where your body’s normally helpful antibodies
<a href="https://en.wikipedia.org/wiki/Anti-NMDA_receptor_encephalitis#Pathophysiology">start acting strangely</a>. This leads to inflammation in the brain. This
short blog briefly discusses some of my experience and prognosis.</p>
<p><strong>Target audience</strong>: Anyone relying on my work for their own projects.</p>
将正则表达式引擎内部机制作为库提供
Translated
AI Summary
eng
[AI 摘要] 文章讲述了为改进组合性与优化而重写 Rust 正则表达式库,从而创建出暴露内部机制的独立库 regex-automata 的过程与API介绍。
View content
<p>过去几年中,我重写了 <a href="https://github.com/rust-lang/regex/">Rust 的 <code>regex</code>
crate</a>,旨在实现更好的内部组合,并在保持正确性的同时更方便地添加优化。在此重写过程中,我创建了一个新的 crate:<a href="https://github.com/rust-lang/regex/tree/master/regex-automata"><code>regex-automata</code></a>,它将 <code>regex</code> crate 的大部分内部机制作为独立的 API 暴露出来供他人使用。据我所知,这是首个以 <code>regex-automata</code> 这样独立版本化的库的形式,将自身内部机制暴露到如此程度的正则表达式库。</p>
<p>这篇博客文章讨论了导致此次重写的问题、重写如何解决这些问题,并对 <code>regex-automata</code> 的 API 进行了导览。</p>
<p><strong>目标读者</strong>:Rust 程序员以及任何对特定有限自动机正则表达式引擎实现方式感兴趣的人。假定读者具有正则表达式的使用经验。</p>
Show original
<p>Over the last several years, I’ve rewritten <a href="https://github.com/rust-lang/regex/">Rust’s <code>regex</code>
crate</a> to enable better internal composition, and to make it
easier to add optimizations while maintaining correctness. In the course of
this rewrite I created a new crate, <a href="https://github.com/rust-lang/regex/tree/master/regex-automata"><code>regex-automata</code></a>, which exposes much
of the <code>regex</code> crate internals as their own APIs for others to use. To my
knowledge, this is the first regex library to expose its internals to the
degree done in <code>regex-automata</code> as a separately versioned library.</p>
<p>This blog post discusses the problems that led to the rewrite, how the rewrite
solved them and a guided tour of <code>regex-automata</code>’s API.</p>
<p><strong>Target audience</strong>: Rust programmers and anyone with an interest in how one
particular finite automata regex engine is implemented. Prior experience wi…
面向 Rust 的字节字符串库
Translated
AI Summary
eng
[AI 摘要] 介绍面向Rust的字节字符串库bstr及其1.0版本的发布。
View content
<p><a href="https://docs.rs/bstr/1.*"><code>bstr</code></a> 是一个面向 Rust 的字节字符串库,其 <a href="https://github.com/BurntSushi/bstr/releases/tag/1.0.0">1.0 版本刚刚发布</a>!它为任意字节序列提供以字符串为导向的操作,但在处理 UTF-8 编码的字节时最为有用。换言之,它提供了一种通过<em>约定</em>来确保内容为 UTF-8 的字符串类型,而 Rust 内置的字符串类型则是<em>保证</em>为 UTF-8 的。</p>
<p>本篇博客将简要介绍其 API,深入探讨创建 <code>bstr</code> 的动机,展示一些使用 <code>bstr</code> 的简短示例程序,并以一些思考作为结尾。</p>
<p><strong>目标读者</strong>:具备一些 UTF-8 背景知识的 Rust 程序员。</p>
Show original
<p><a href="https://docs.rs/bstr/1.*"><code>bstr</code></a> is a byte string library for Rust and <a href="https://github.com/BurntSushi/bstr/releases/tag/1.0.0">its 1.0 version has
just been released</a>! It provides string oriented operations on
arbitrary sequences of bytes, but is most useful when those bytes are UTF-8. In
other words, it provides a string type that is UTF-8 by <em>convention</em>, where as
Rust’s built-in string types are <em>guaranteed</em> to be UTF-8.</p>
<p>This blog will briefly describe the API, do a deep dive on the motivation for
creating <code>bstr</code>, show some short example programs using <code>bstr</code> and conclude
with a few thoughts.</p>
<p><strong>Target audience</strong>: Rust programmers with some background knowledge of UTF-8.</p>
在Rust中使用unwrap()是可以的
Translated
AI Summary
eng
[AI 摘要] 本文讨论了在Rust测试代码或panic表示存在bug时使用unwrap()是可接受的,并澄清了相关困惑。
View content
<p>在Rust 1.0发布前一天,我发布了<a href="https://blog.burntsushi.net/rust-error-handling/">一篇介绍错误处理基础的博文</a>。文章中部一个特别重要但篇幅较短的章节名为“<a href="https://blog.burntsushi.net/rust-error-handling/#a-brief-interlude-unwrapping-isnt-evil">解包(unwrapping)并非邪恶</a>”。该章节简要说明:总体而言,如果在测试/示例代码中使用<code>unwrap()</code>,或者当panic表示存在错误时使用它,是完全可以的。</p>
<p>我至今基本仍持这一观点。这一实践在Rust标准库及众多核心生态库中都有应用。(而且这种应用早于我的博文发布。)然而,关于何时可以或不可以使用<code>unwrap()</code>,似乎仍存在广泛的困惑。本文将更详细地讨论这一点,并具体回应我见过的一些立场。</p>
<p>这篇博文在一定程度上是以常见问题解答(FAQ)的形式撰写的,但建议按顺序阅读。每个问题都建立在前一个问题的基础上。</p>
<p><strong>目标受众</strong>:主要是Rust程序员,但我希望提供了足够的背景信息,使本文阐述的原则适用于任何程序员。尽管对于使用不同错误处理机制(如异常)的语言来说,可能难以进行明显映射。</p>
Show original
<p>One day before Rust 1.0 was released, I published a
<a href="https://blog.burntsushi.net/rust-error-handling/">blog post covering the fundamentals of error handling</a>.
A particularly important but small section buried in the middle of the article
is named “<a href="https://blog.burntsushi.net/rust-error-handling/#a-brief-interlude-unwrapping-isnt-evil">unwrapping isn’t evil</a>”. That section briefly
described that, broadly speaking, using <code>unwrap()</code> is okay if it’s in
test/example code or when panicking indicates a bug.</p>
<p>I generally still hold that belief today. That belief is put into practice in
Rust’s standard library and in many core ecosystem crates. (And that practice
predates my blog post.) Yet, there still seems to be widespread confusion about
when it is and isn’t okay to use <code>unwrap()</code>. This post will talk about that
in more detail and respond specifically to a number of positions I’ve seen
expressed.…
在 System76 Darter Pro 上安装 Archlinux
Translated
AI Summary
eng
[AI 摘要] 本文回顾了作者在 System76 Darter Pro 上安装和使用 Archlinux 的体验。
View content
<p>这是一篇关于我在 System76 Darter Pro(型号:darp6)上配置 Archlinux 的简短回顾,并附带一些对这款笔记本电脑的总体看法。这是自<a href="https://burntsushi.net/lenovo-thinkpad-t430-archlinux">2012年7月购买 ThinkPad T430</a>以来,我的首次笔记本电脑升级。</p>
<p>目标受众:正在寻找兼容 Linux 笔记本电脑的 Archlinux 用户。</p>
Show original
<p>This is a quick post reviewing my Archlinux setup on a System76 Darter Pro
(model: darp6) with Coreboot, along with some thoughts about the laptop in
general. This is my first laptop upgrade since I
<a href="https://burntsushi.net/lenovo-thinkpad-t430-archlinux">purchased a ThinkPad T430 in July 2012</a></p>
<p>Target audience: Archlinux users looking for a compatible Linux laptop.</p>
我的自由与开源软件故事
Translated
AI Summary
eng
[AI 摘要] 这是一篇个人反思文章,作者分享了自己与自由与开源软件的关系,旨在促进社区的理解和共情。
View content
<p>我想打破以往专注于纯技术内容的传统,分享一点我个人与自由与开源软件的关系。虽然每个人都不尽相同,但我希望通过分享我的视角,能够促进理解、共情和信任。</p>
<p>这并非旨在直接回应任何其他维护者的行为,也不应被解读为自由与开源软件领域理想行为的规范。这更多是个人反思,希望能启发他人也反思自己与自由与开源软件的关系。成为优秀的自由与开源软件维护者没有唯一正确的道路,我们都有自己的应对方式。</p>
<p>这绝不是在呼吁寻求帮助,重点是理解。这不是关于改变自由与开源软件经济模式的恳求,不是关于改善我心理健康的头脑风暴,也不是关于招募更多维护者。这是关于分享我的故事,并试图增进自由与开源软件界成员之间的共情。</p>
<p><strong>目标读者</strong>:所有参与自由与开源软件的人。
Show original
<p>I’d like to break from my normal tradition of focusing almost strictly on
technical content and share a bit of my own personal relationship with Free
and Open Source Software (FOSS). While everyone is different, my hope is that
sharing my perspective will help build understanding, empathy and trust.</p>
<p>This is not meant to be a direct response to the behavior of any other
maintainer. Nor should it be read as a prescription on the ideal behavior of
someone in FOSS. This is meant more as a personal reflection with the hope that
others will use it to reflect on their own relationship with FOSS. There is no
one true path to being a good FOSS maintainer. We all have our own coping
mechanisms.</p>
<p>This is also emphatically not meant as a call for help. This is about
understanding. This is not about a plea to change the economics of FOSS. This
is not about brainstorming ways to improve my mental health. This is not about
bringing on more maintainers. It’s about sharing m…
Rust 与 CSV 解析
Translated
AI Summary
eng
[AI 摘要] 这是一篇面向 Rust 初学者的 CSV 数据读写入门教程,以示例为主讲解基础概念。
View content
<p>随着 <code>csv 1.0</code> 的发布,现在正是撰写一个关于如何在 Rust 中读写 CSV 数据教程的好时机。本教程面向 Rust 初学者,因此包含大量示例,并花时间讲解基本概念。经验丰富的 Rust 开发者可能会觉得部分内容有用,但快速浏览一遍可能更为合适。</p>
<p>关于 Rust 的介绍,请参阅<a href="https://doc.rust-lang.org/book/second-edition/">官方书籍</a>。如果您尚未编写过任何 Rust 代码,但已经在其他语言中写过代码,那么本教程可能无需您先阅读该书就能理解。</p>
<p>该 CSV 库可在 <a href="https://github.com/BurntSushi/rust-csv">Github 上获取</a>,并提供<a href="https://docs.rs/csv">全面的 API 文档</a>。</p>
<p>最后,本文的某个版本已作为<a href="https://docs.rs/csv/1.0.0/csv/tutorial/index.html">教程</a>收录在 API 文档中,并且更有可能随着时间的推移进行更新。</p>
<p><strong>目标受众</strong>:Rust 初学者。</p>
Show original
<p>With <code>csv 1.0</code> just released, the time is ripe for a tutorial on how to read
and write CSV data in Rust. This tutorial is targeted toward beginning Rust
programmers, and is therefore full of examples and spends some time on basic
concepts. Experienced Rust programmers may find parts of this useful, but would
probably be happier with a quick skim.</p>
<p>For an introduction to Rust, please see the
<a href="https://doc.rust-lang.org/book/second-edition/">official book</a>.
If you haven’t written any Rust code yet but have written code in another
language, then this tutorial might be accessible to you without needing to read
the book first.</p>
<p>The CSV library is
<a href="https://github.com/BurntSushi/rust-csv">available on Github</a>
and has
<a href="https://docs.rs/csv">comprehensive API documentation</a>.</p>
<p>Finally, a version of this blog post is included as a
<a href="https://docs.rs/csv/1.0.0/csv/tutorial/index.html">tutorial</a>
in the API documentation, …
ripgrep 速度超越 {grep、ag、git grep、ucg、pt、sift}
Translated
AI Summary
eng
[AI 摘要] 本文介绍并基准测试了用Rust编写的高速跨平台命令行搜索工具ripgrep,论证其在性能与Unicode支持上优于同类工具。
View content
<p>在本文中,我将介绍一个新的命令行搜索工具——<a href="https://github.com/BurntSushi/ripgrep"><code>ripgrep</code></a>,它结合了<a href="https://github.com/ggreer/the_silver_searcher">The Silver Searcher</a>(一个<a href="http://beyondgrep.com/"><code>ack</code></a>克隆)的易用性以及GNU grep的原始性能。<code>ripgrep</code>速度快、跨平台(提供适用于Linux、Mac和Windows的二进制文件),并使用<a href="https://www.rust-lang.org">Rust</a>语言编写。</p>
<p><code>ripgrep</code>可在<a href="https://github.com/BurntSushi/ripgrep">Github</a>上获取。</p>
<p>我们将尝试做一件看似不可能的事:对多种流行的代码搜索工具进行一次公平的基准比较。具体来说,我们将深入研究一系列25个基准测试,以证实以下主张:</p>
<ul>
<li>无论是搜索单个文件<em>还是</em>海量文件目录,在性能和正确性方面,没有其他工具能明显超越<code>ripgrep</code>。</li>
<li><code>ripgrep</code>是唯一一个提供正确的Unicode支持且不会让你为此付出高昂性能代价的工具。</li>
<li>那些同时搜索多个文件的工具,如果使用内存映射,通常<em>更慢</em>,而不是更快。</li>
</ul>
<p>作为过去2.5年在业余时间使用Rust处理文本搜索的工作者,以及<code>ripgrep</code>和<a href="https://github.com/rust-lang-nursery/regex">底层正则表达式引擎</a>的作者,我将借此机会深入剖析每个代码搜索工具的性能。每个基准测试都将受到审视!</p>
<p><strong>目标读者</strong>:熟悉Unicode、编程,并在命令行工作方面有一定经验的人士。</p>
<p><strong>注意</s…
Show original
<p>In this article I will introduce a new command line search tool,
<a href="https://github.com/BurntSushi/ripgrep"><code>ripgrep</code></a>,
that combines the usability of
<a href="https://github.com/ggreer/the_silver_searcher">The Silver Searcher</a>
(an <a href="http://beyondgrep.com/"><code>ack</code></a> clone) with the
raw performance of GNU grep. <code>ripgrep</code> is fast, cross platform (with binaries
available for Linux, Mac and Windows) and written in
<a href="https://www.rust-lang.org">Rust</a>.</p>
<p><code>ripgrep</code> is available on
<a href="https://github.com/BurntSushi/ripgrep">Github</a>.</p>
<p>We will attempt to do the impossible: a fair benchmark comparison between
several popular code search tools. Specifically, we will dive into a series of
25 benchmarks that substantiate the following claims:</p>
<ul>
<li>For both searching single files <em>and</em> huge directories of files, no other
tool obviously stands above <code>ripgrep</code> in either performance or…
使用自动机和Rust索引16亿个键
Translated
AI Summary
eng
[AI 摘要] 本文介绍如何使用有限状态机和Rust来高效索引和搜索大规模字符串数据集,例如超过16亿个URL。
View content
<p>事实证明,有限状态机除了用于表达计算外还有其他用途。有限状态机也可用于紧凑地表示可快速搜索的字符串有序集合或映射。</p>
<p>在本文中,我将向你介绍作为<em>数据结构</em>的有限状态机,用于表示有序集合和映射。这包括介绍一个用Rust编写的实现,即<a href="https://github.com/BurntSushi/fst"><code>fst</code> crate</a>。它附带<a href="https://burntsushi.net/rustdoc/fst/">完整的API文档</a>。我还会向你展示如何使用一个简单的命令行工具来构建它们。最后,我将讨论几个实验,最终实现对<a href="http://blog.commoncrawl.org/2015/08/july-2015-crawl-archive-available/">2015年7月Common Crawl归档</a>中超过16亿个URL(134 GB)的索引。</p>
<p>本文介绍的技术也是<a href="http://blog.mikemccandless.com/2010/12/using-finite-state-transducers-in.html">Lucene表示其部分倒排索引</a>的方式。</p>
<p>过程中,我们将讨论内存映射、自动机与正则表达式的交集运算、基于Levenshtein距离的模糊搜索以及流式集合操作。</p>
<p><strong>目标读者</strong>:熟悉编程和基本数据结构。无需自动机理论或Rust经验。</p>
Show original
<p>It turns out that finite state machines are useful for things other than
expressing computation. Finite state machines can also be used to compactly
represent ordered sets or maps of strings that can be searched very quickly.</p>
<p>In this article, I will teach you about finite state machines as a <em>data
structure</em> for representing ordered sets and maps. This includes introducing
an implementation written in Rust called the
<a href="https://github.com/BurntSushi/fst"><code>fst</code> crate</a>.
It comes with
<a href="https://burntsushi.net/rustdoc/fst/">complete API documentation</a>.
I will also show you how to build them using a simple command line tool.
Finally, I will discuss a few experiments culminating in indexing over
1,600,000,000 URLs (134 GB) from the
<a href="http://blog.commoncrawl.org/2015/08/july-2015-crawl-archive-available/">July 2015 Common Crawl Archive</a>.</p>
<p>The technique presented in this article is also how
<a href="http://blog.mikemccandless.com/2…
Rust 中的错误处理
Translated
AI Summary
eng
[AI 摘要] 本文全面介绍了 Rust 中的错误处理方法,包括常见问题和使用标准库的技巧。
View content
<p>和大多数编程语言一样,Rust 鼓励程序员以特定的方式处理错误。一般来说,错误处理分为两大类:异常和返回值。Rust 选择了返回值。</p>
<p>在这篇文章中,我打算全面介绍如何在 Rust 中处理错误。不仅如此,我将尝试逐步引入错误处理,以便你能获得一个扎实的实践知识,了解所有部分如何协同工作。</p>
<p>如果处理不当,Rust 中的错误处理可能会冗长且令人烦恼。本文将探讨这些障碍,并展示如何使用标准库使错误处理变得简洁和符合人体工程学。</p>
<p><strong>目标读者</strong>:那些刚接触 Rust 且不了解其错误处理惯用法的人。对 Rust 有一些熟悉会有帮助。(本文大量使用了一些标准 trait,并非常轻量地使用了闭包和宏。)</p>
<p><strong>更新(2018/04/14)</strong>:示例已转换为使用 <code>?</code>,并添加了一些文本以提供更改的历史背景。</p>
<p><strong>更新(2020/01/03)</strong>:移除了使用 <a href="https://crates.io/crates/failure"><code>failure</code></a> 的推荐,并替换为推荐使用 <code>Box<Error + Send + Sync></code> 或 <a href="https://crates.io/crates/anyhow"><code>anyhow</code></a>。</p>
Show original
<p>Like most programming languages, Rust encourages the programmer to handle
errors in a particular way. Generally speaking, error handling is divided into
two broad categories: exceptions and return values. Rust opts for return
values.</p>
<p>In this article, I intend to provide a comprehensive treatment of how to deal
with errors in Rust. More than that, I will attempt to introduce error handling
one piece at a time so that you’ll come away with a solid working knowledge of
how everything fits together.</p>
<p>When done naively, error handling in Rust can be verbose and annoying. This
article will explore those stumbling blocks and demonstrate how to use the
standard library to make error handling concise and ergonomic.</p>
<p><strong>Target audience</strong>: Those new to Rust that don’t know its error handling
idioms yet. Some familiarity with Rust is helpful. (This article makes heavy
use of some standard traits and some very light use of closures and macros.)</p>
<p><…
Rust 的语法扩展与正则表达式
Translated
AI Summary
eng
[AI 摘要] 本文介绍了如何通过 Rust 语法扩展,在编译时将正则表达式编译为原生代码,并确保其与运行时编译版本拥有相同的 API。
View content
<p><strong>警告:</strong> <!-- raw HTML omitted -->2018-04-12<!-- raw HTML omitted -->:本文的代码片段已不再可用。这也没关系,因为它们都依赖于一个多年前就不存在的不稳定内部编译器接口。</p>
<p>几周前,我开始着手为 <a href="http://www.rust-lang.org/">Rust</a> 发行版添加正则表达式功能,其实现和功能集主要参考了 <a href="http://swtch.com/~rsc/regexp/">Russ Cox 的 RE2</a>。它最近已被加入到 <a href="http://static.rust-lang.org/doc/master/regex/index.html">Rust 发行版</a>中。</p>
<p>这个正则表达式 crate 包含一个语法扩展,能在 Rust 程序编译时将正则表达式编译为原生 Rust 代码。这可以被视为“提前编译”,或类似于<a href="http://en.wikipedia.org/wiki/Compile_time_function_execution">编译时函数执行</a>。这些特殊原生编译的正则表达式拥有与在运行时编译的正则表达式<em>完全相同</em>的 API。</p>
<p>在本文中,我将概述我的实现策略——包括如何编写 Rust 语法扩展的代码示例——并描述我如何能够实现编译时编译的正则表达式与运行时编译的正则表达式之间完全相同的 API。</p>
Show original
<p><strong>WARNING:</strong> <!-- raw HTML omitted -->2018-04-12<!-- raw HTML omitted -->: The code snippets for this post are no longer
available. This is just as well anyway, since they all depended on an unstable
internal compiler interface, which hasn’t existed for years.</p>
<p>A few weeks ago, I set out to add regular expressions to the
<a href="http://www.rust-lang.org/">Rust</a>
distribution with an implementation and feature set heavily inspired by
<a href="http://swtch.com/~rsc/regexp/">Russ Cox’s RE2</a>.
It was just recently added to the
<a href="http://static.rust-lang.org/doc/master/regex/index.html">Rust distribution</a>.</p>
<p>This regex crate includes a syntax extension that compiles a regular expression
to native Rust code <em>when a Rust program is compiled</em>. This can be thought of
as “ahead of time” compilation or
something similar to <a href="http://en.wikipedia.org/wiki/Compile_time_function_execution">compile time function
execution</…
在Go中编写类型参数化函数
Translated
AI Summary
eng
[AI 摘要] 本文介绍如何使用Go的`ty`包编写类型参数化函数,在保持运行时类型安全的同时简化调用方式。
View content
<p>Go在编译时实现类型安全多态的唯一机制是结构化子类型,本文不会改变这一点。相反,我将介绍一个名为<code>ty</code>的工具包,它提供在Go中编写类型参数化函数的方案,既能保持<strong>运行时</strong>类型安全,又方便调用方使用。</p>
Show original
<p>Go’s only method of compile time safe polymorphism is structural subtyping, and
this article will do nothing to change that. Instead, I’m going to present a
package <code>ty</code> with facilities to write type parametric functions in Go that
maintain <strong>run time</strong> type safety, while also being convenient for the
caller to use.</p>
介绍NFLGame:通过程序化方式获取实时NFL比赛统计数据
Translated
AI Summary
eng
[AI 摘要] 一位程序员为解决NFL数据获取难题,启动了新的开源程序库项目。
View content
<p>作为一名程序员和梦幻橄榄球迷,我为我们获取机器可读数据所需付出的努力感到尴尬。开源软件的匮乏使社区充斥着劣质工具,更重要的是,这阻碍了利用便捷统计数据本可实现的许多真正有趣的功能。许多工具要么过时,要么无法运行;即便能用,它们也是闭源的,且通常需要付费。</p>
<p>昨天,我开始着手开发一个新的程序库,希望能改善这种可悲的现状。</p>
Show original
<p>As a programmer and a fantasy football addict, I am embarassed by the means
through which we must expend ourselves to get data in a machine readable form.
This lack of open source software cripples the community with sub-standard
tools, and most importantly, detracts from some really cool and fun things that
could be done with easily available statistics. Many tools are either out-dated
or broken, or if they work, they are closed source and often cost money.</p>
<p>Yesterday I started work on a new library package that I hope will start to
improve this sorry state of affairs.</p>
在联想ThinkPad T430上运行Arch Linux
Translated
AI Summary
eng
[AI 摘要] 本文记录了在联想ThinkPad T430上成功部署Arch Linux系统的个人经验与配置笔记。
View content
<p>总之,Arch Linux运行得相当出色。以下是在联想ThinkPad T430上安装、配置、调优和使用Arch Linux时,我整理的大致笔记。</p>
Show original
<p>In sum, Archlinux is working beautifully. What follows is a rough run down of
my notes while installing, configuring, tuning and using Archlinux on the
Lenovo Thinkpad T430.</p>
将Go程序守护进程化(BSD风格rc.d示例)
Translated
AI Summary
eng
[AI 摘要] Go程序的多线程特性使得fork守护进程化困难,文章建议用nohup来解决这个问题。
View content
<p>Go语言本质上是多线程的。这使得通过fork方式将Go程序守护进程化的传统方法有点困难。</p>
<p>为了解决这个问题,你可以尝试一种简单的方法,即将Go程序放在后台运行,并让它<a href="http://en.wikipedia.org/wiki/Nohup">忽略HUP信号</a>:</p>
Show original
<p>Go, by its very nature, is multithreaded. This makes a traditional approach of
daemonizing Go programs by forking a bit difficult.</p>
<p>To get around this, you could try something as simple as backgrounding your Go
program and instructing it to <a href="http://en.wikipedia.org/wiki/Nohup">ignore the HUP
signal</a>:</p>