Skip to content

Commit

Permalink
deploy: b16e018
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsayleung committed Sep 19, 2024
1 parent f8f19c8 commit 6353b44
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<sitemap>
<loc>https://ramsayleung.github.io/zh/sitemap.xml</loc>

<lastmod>2024-09-18T23:53:02-07:00</lastmod>
<lastmod>2024-09-18T23:58:05-07:00</lastmod>

</sitemap>

Expand Down
2 changes: 1 addition & 1 deletion zh/about_me_zh/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion zh/archives/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion zh/categories/rust/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!doctype html><html lang=zh dir=auto><head><meta charset=utf-8><meta http-equiv=x-ua-compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name=robots content="index, follow"><title>rust | 自由庄园</title><meta name=keywords content><meta name=description content="In Pursuit of Hubris"><meta name=author content="Ramsay Leung"><link rel=canonical href=https://ramsayleung.github.io/zh/categories/rust/><meta name=google-site-verification content="XYZabc"><meta name=yandex-verification content="XYZabc"><meta name=msvalidate.01 content="XYZabc"><link crossorigin=anonymous href=/assets/css/stylesheet.5cfc680b1eeaeef9efbced92d46c2a9e876b72ee14fba85846afc4cff9e6e6f8.css integrity="sha256-XPxoCx7q7vnvvO2S1Gwqnodrcu4U+6hYRq/Ez/nm5vg=" rel="preload stylesheet" as=style><link rel=icon href=https://ramsayleung.github.io/favicon.ico><link rel=icon type=image/png sizes=16x16 href=https://ramsayleung.github.io/favicon-16x16.png><link rel=icon type=image/png sizes=32x32 href=https://ramsayleung.github.io/favicon-32x32.png><link rel=apple-touch-icon href=https://ramsayleung.github.io/apple-touch-icon.png><link rel=mask-icon href=https://ramsayleung.github.io/%3Clink%20/%20abs%20url%3E><meta name=theme-color content="#2e2e33"><meta name=msapplication-TileColor content="#2e2e33"><link rel=alternate type=application/rss+xml href=https://ramsayleung.github.io/zh/categories/rust/index.xml><link rel=alternate hreflang=en href=https://ramsayleung.github.io/en/categories/rust/><link rel=alternate hreflang=zh href=https://ramsayleung.github.io/zh/categories/rust/><noscript><style>#theme-toggle,.top-link{display:none}</style><style>@media(prefers-color-scheme:dark){:root{--theme:rgb(29, 30, 32);--entry:rgb(46, 46, 51);--primary:rgb(218, 218, 219);--secondary:rgb(155, 156, 157);--tertiary:rgb(65, 66, 68);--content:rgb(196, 196, 197);--hljs-bg:rgb(46, 46, 51);--code-bg:rgb(55, 56, 62);--border:rgb(51, 51, 51)}.list{background:var(--theme)}.list:not(.dark)::-webkit-scrollbar-track{background:0 0}.list:not(.dark)::-webkit-scrollbar-thumb{border-color:var(--theme)}}</style></noscript><script async src="https://www.googletagmanager.com/gtag/js?id=G-9MG65HQHEL"></script>
<script>var doNotTrack=!1;if(!doNotTrack){window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments)}gtag("js",new Date),gtag("config","G-9MG65HQHEL",{anonymize_ip:!1})}</script><meta property="og:title" content="rust"><meta property="og:description" content="In Pursuit of Hubris"><meta property="og:type" content="website"><meta property="og:url" content="https://ramsayleung.github.io/zh/categories/rust/"><meta property="og:image" content="https://ramsayleung.github.io/%3Clink%20or%20path%20of%20image%20for%20opengraph,%20twitter-cards%3E"><meta property="og:site_name" content="自由庄园"><meta name=twitter:card content="summary_large_image"><meta name=twitter:image content="https://ramsayleung.github.io/%3Clink%20or%20path%20of%20image%20for%20opengraph,%20twitter-cards%3E"><meta name=twitter:title content="rust"><meta name=twitter:description content="In Pursuit of Hubris"></head><body class=list id=top><script>localStorage.getItem("pref-theme")==="dark"?document.body.classList.add("dark"):localStorage.getItem("pref-theme")==="light"?document.body.classList.remove("dark"):window.matchMedia("(prefers-color-scheme: dark)").matches&&document.body.classList.add("dark")</script><header class=header><nav class=nav><div class=logo><a href=https://ramsayleung.github.io/zh/ accesskey=h title="Home (Alt + H)"><img src=https://ramsayleung.github.io/apple-touch-icon.png alt aria-label=logo height=35>Home</a><div class=logo-switches><button id=theme-toggle accesskey=t title="(Alt + T)"><svg id="moon" xmlns="http://www.w3.org/2000/svg" width="24" height="18" viewBox="0 0 24 24" fill="none" stroke="currentcolor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12.79A9 9 0 1111.21 3 7 7 0 0021 12.79z"/></svg><svg id="sun" xmlns="http://www.w3.org/2000/svg" width="24" height="18" viewBox="0 0 24 24" fill="none" stroke="currentcolor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></svg></button><ul class=lang-switch><li>|</li><li><a href=https://ramsayleung.github.io/en/ title=English aria-label=English>En</a></li></ul></div></div><ul id=menu><li><a href=https://ramsayleung.github.io/zh/archives/ title=归档><span>归档</span></a></li><li><a href=https://ramsayleung.github.io/zh/search/ title=搜索><span>搜索</span></a></li><li><a href=https://ramsayleung.github.io/zh/categories/ title=目录><span>目录</span></a></li><li><a href=https://ramsayleung.github.io/zh/tags/ title=标签><span>标签</span></a></li><li><a href=https://ramsayleung.github.io/zh/about_me_zh/ title=关于><span>关于</span></a></li></ul></nav></header><main class=main><header class=page-header><div class=breadcrumbs><a href=https://ramsayleung.github.io/zh/>主页</a></div><h1>rust
<a href=/zh/categories/rust/index.xml title=RSS aria-label=RSS><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentcolor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" height="23"><path d="M4 11a9 9 0 019 9"/><path d="M4 4a16 16 0 0116 16"/><circle cx="5" cy="19" r="1"/></svg></a></h1></header><article class="post-entry tag-entry"><header class=entry-header><h2>使用Rust的Iterator优雅解决FizzBuzz问题</h2></header><div class=entry-content><p>1 前言 按照维基百科的说法,FizzBuzz问题 是一个简单但是常见的面试编程问题(可能以前常见,现在都是考Leetcode了,这种连Easy 都...</p></div><footer class=entry-footer><span title='2024-09-18 22:46:00 -0700 -0700'>九月 18, 2024</span>&nbsp;·&nbsp;4 分钟&nbsp;·&nbsp;1719 字&nbsp;·&nbsp;Ramsay Leung</footer><a class=entry-link aria-label="post link to 使用Rust的Iterator优雅解决FizzBuzz问题" href=https://ramsayleung.github.io/zh/post/2024/%E4%BD%BF%E7%94%A8rust%E7%9A%84iterator%E8%A7%A3%E5%86%B3fizzbuzz%E9%97%AE%E9%A2%98/></a></article><article class="post-entry tag-entry"><header class=entry-header><h2>Rust模拟C++的函数重载</h2></header><div class=entry-content><p>1 函数重载(function overloading) 所谓的函数重载,指的是某些语言支持创建函数名相同,但函数签名不同的多个函数,所谓的函数签名,既指参数类型,也指...</p></div><footer class=entry-footer><span title='2024-08-30 22:23:00 -0700 -0700'>八月 30, 2024</span>&nbsp;·&nbsp;2 分钟&nbsp;·&nbsp;827 字&nbsp;·&nbsp;Ramsay Leung</footer><a class=entry-link aria-label="post link to Rust模拟C++的函数重载" href=https://ramsayleung.github.io/zh/post/2024/rust%E6%A8%A1%E6%8B%9Fc++%E7%9A%84%E5%87%BD%E6%95%B0%E9%87%8D%E8%BD%BD/></a></article><article class="post-entry tag-entry"><header class=entry-header><h2>Let's make everything iterable</h2></header><div class=entry-content><p>Iterate through pagination in the Rest API
<a href=/zh/categories/rust/index.xml title=RSS aria-label=RSS><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentcolor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" height="23"><path d="M4 11a9 9 0 019 9"/><path d="M4 4a16 16 0 0116 16"/><circle cx="5" cy="19" r="1"/></svg></a></h1></header><article class="post-entry tag-entry"><header class=entry-header><h2>使用Rust的Iterator优雅解决FizzBuzz问题</h2></header><div class=entry-content><p>1 前言 按照维基百科的说法,FizzBuzz问题 是一个简单但是常见的面试编程问题(可能以前常见,现在都是考Leetcode了,这种连Easy 都...</p></div><footer class=entry-footer><span title='2024-09-18 22:46:00 -0700 -0700'>九月 18, 2024</span>&nbsp;·&nbsp;4 分钟&nbsp;·&nbsp;1700 字&nbsp;·&nbsp;Ramsay Leung</footer><a class=entry-link aria-label="post link to 使用Rust的Iterator优雅解决FizzBuzz问题" href=https://ramsayleung.github.io/zh/post/2024/%E4%BD%BF%E7%94%A8rust%E7%9A%84iterator%E8%A7%A3%E5%86%B3fizzbuzz%E9%97%AE%E9%A2%98/></a></article><article class="post-entry tag-entry"><header class=entry-header><h2>Rust模拟C++的函数重载</h2></header><div class=entry-content><p>1 函数重载(function overloading) 所谓的函数重载,指的是某些语言支持创建函数名相同,但函数签名不同的多个函数,所谓的函数签名,既指参数类型,也指...</p></div><footer class=entry-footer><span title='2024-08-30 22:23:00 -0700 -0700'>八月 30, 2024</span>&nbsp;·&nbsp;2 分钟&nbsp;·&nbsp;827 字&nbsp;·&nbsp;Ramsay Leung</footer><a class=entry-link aria-label="post link to Rust模拟C++的函数重载" href=https://ramsayleung.github.io/zh/post/2024/rust%E6%A8%A1%E6%8B%9Fc++%E7%9A%84%E5%87%BD%E6%95%B0%E9%87%8D%E8%BD%BD/></a></article><article class="post-entry tag-entry"><header class=entry-header><h2>Let's make everything iterable</h2></header><div class=entry-content><p>Iterate through pagination in the Rest API
1 Preface About 4 months ago, icewind1991 created an exciting PR that adding Stream/Iterator based versions of methods with paginated results, which makes enpoints in Rspotify more much ergonomic to use, and Mario completed this PR.
In order to know what this PR brought to us, we have to go back to the orignal story, the paginated results in Spotify’s Rest API.
2 Orignal Story Taking the artist_albums as example, it gets Spotify catalog information about an artist’s albums....</p></div><footer class=entry-footer><span title='2021-04-29 11:48:00 +0800 +0800'>四月 29, 2021</span>&nbsp;·&nbsp;5 分钟&nbsp;·&nbsp;1004 字&nbsp;·&nbsp;Ramsay Leung</footer><a class=entry-link aria-label="post link to Let's make everything iterable" href=https://ramsayleung.github.io/zh/post/2021/iterate_through_pagination_api/></a></article><article class="post-entry tag-entry"><header class=entry-header><h2>Serde Tricks</h2></header><div class=entry-content><p>The lesson learned from refactoring rspotify
Expand Down
8 changes: 4 additions & 4 deletions zh/categories/rust/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="c1">// ... and now we&#39;re done
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="fm">assert_eq!</span><span class="p">(</span><span class="nb">None</span><span class="p">,</span><span class="w"> </span><span class="n">four_fours</span><span class="p">.</span><span class="n">next</span><span class="p">());</span><span class="w">
</span></span></span></code></pre></div><h3 id="once"><!-- raw HTML omitted -->3.2<!-- raw HTML omitted --> once</h3>
<p>有生成无限个元素的 <code>iterator=,自然就有只生成一个元素的 =iterator</code>, 那就是 <code>once()</code>, 这个 <code>iterator</code> 只会返回一个指定的元素。 <!-- raw HTML omitted --></p>
<p>所以 <code>once(&quot;fizz&quot;)</code> 就是创建一个只会返回一个 &ldquo;fizz&rdquo; 的 <code>iterator</code> : <!-- raw HTML omitted --></p>
<p>有生成无限个元素的 <code>iterator=, 自然就有只生成一个元素的 =iterator</code>, 那就是 <code>once()</code>, 这个 <code>iterator</code> 只会返回一个指定的元素。 <!-- raw HTML omitted --></p>
<p>所以 <code>once(&quot;fizz&quot;)</code> 就是创建一个只会返回一个 <code>&quot;fizz&quot;</code> 的 <code>iterator</code> : <!-- raw HTML omitted --></p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">iter</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="c1">// one is the loneliest number
Expand Down Expand Up @@ -118,7 +118,7 @@
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="fm">assert_eq!</span><span class="p">(</span><span class="n">spin</span><span class="p">.</span><span class="n">next</span><span class="p">(),</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="o">&amp;</span><span class="s">&#34;West&#34;</span><span class="p">));</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="fm">assert_eq!</span><span class="p">(</span><span class="n">spin</span><span class="p">.</span><span class="n">next</span><span class="p">(),</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="o">&amp;</span><span class="s">&#34;North&#34;</span><span class="p">));</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="fm">assert_eq!</span><span class="p">(</span><span class="n">spin</span><span class="p">.</span><span class="n">next</span><span class="p">(),</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="o">&amp;</span><span class="s">&#34;East&#34;</span><span class="p">));</span><span class="w">
</span></span></span></code></pre></div><p>把4个 iterator 组合起来的 <code>repeat(&quot;&quot;).take(2).chain(once(&quot;fizz&quot;)).cycle();</code> 表达式的意思就是, 返回一个 iterator, 这个 iterator 无限循环: <code>&quot;&quot; &quot;&quot; &quot;fizz&quot; &quot;&quot; &quot;&quot; &quot;fizz&quot; ...</code> <!-- raw HTML omitted --></p>
</span></span></span></code></pre></div><p>把4个 iterator 组合起来的 <code>repeat(&quot;&quot;).take(2).chain(once(&quot;fizz&quot;)).cycle();</code> 表达式的意思就是: 返回一个 iterator, 这个 iterator 无限循环: <code>&quot;&quot; &quot;&quot; &quot;fizz&quot; &quot;&quot; &quot;&quot; &quot;fizz&quot; ...</code> <!-- raw HTML omitted --></p>
<h3 id="zip"><!-- raw HTML omitted -->3.5<!-- raw HTML omitted --> zip</h3>
<p><code>zip</code> iterator 的含义就是 &ldquo;zips up&rdquo;, 翻译过来就是拉上拉链,它的作用就是把两个 <code>iterator</code> 像拉链一样拉起来,返回一个 iterator,用代码来解释会更直观: <!-- raw HTML omitted --></p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="kd">let</span><span class="w"> </span><span class="n">a1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">];</span><span class="w">
Expand All @@ -130,7 +130,7 @@
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="fm">assert_eq!</span><span class="p">(</span><span class="n">iter</span><span class="p">.</span><span class="n">next</span><span class="p">(),</span><span class="w"> </span><span class="nb">Some</span><span class="p">((</span><span class="o">&amp;</span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="mi">5</span><span class="p">)));</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="fm">assert_eq!</span><span class="p">(</span><span class="n">iter</span><span class="p">.</span><span class="n">next</span><span class="p">(),</span><span class="w"> </span><span class="nb">Some</span><span class="p">((</span><span class="o">&amp;</span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="mi">6</span><span class="p">)));</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="fm">assert_eq!</span><span class="p">(</span><span class="n">iter</span><span class="p">.</span><span class="n">next</span><span class="p">(),</span><span class="w"> </span><span class="nb">None</span><span class="p">);</span><span class="w">
</span></span></span></code></pre></div><p><code>zip</code> 就是把 <code>a1</code> 和 <code>a2</code> 两个iterator 「拉起来」了,每次返回一对的元素. 所以 =fizzes.zip(buzzes)=,就是合并了两个 iterator : <!-- raw HTML omitted --></p>
</span></span></span></code></pre></div><p><code>zip</code> 就是把 <code>a1</code> 和 <code>a2</code> 两个iterator 「拉起来」了,每次返回一对的元素. 所以 <code>fizzes.zip(buzzes)</code> ,就是合并了两个 iterator : <!-- raw HTML omitted --></p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="cl"><span class="c1">// fizzes: &#34;&#34; &#34;&#34; &#34;fizz&#34; &#34;&#34; &#34;&#34; &#34;fizz&#34; &#34;&#34; &#34;&#34; &#34;fizz&#34; ..
</span></span></span><span class="line"><span class="cl"><span class="c1">// buzzes: &#34;&#34; &#34;&#34; &#34;&#34; &#34;&#34; &#34;buzz&#34; &#34;&#34; &#34;&#34; &#34;&#34; &#34;&#34; &#34;buzz&#34;
</span></span></span><span class="line"><span class="cl"><span class="c1">// fizzes_buzzes: (&#34;&#34; &#34;&#34;) (&#34;&#34; &#34;&#34;) (&#34;fizz&#34; &#34;&#34;) (&#34;&#34; &#34;&#34;) (&#34;&#34; &#34;buzz&#34;) ...
Expand Down
Loading

0 comments on commit 6353b44

Please sign in to comment.