Skip to content

Commit

Permalink
deploy: 1e73222
Browse files Browse the repository at this point in the history
  • Loading branch information
IceOfSummer committed Mar 29, 2024
1 parent 7d8e40e commit 22f24c4
Show file tree
Hide file tree
Showing 21 changed files with 617 additions and 19 deletions.
2 changes: 2 additions & 0 deletions 2023/12/04/rust/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ <h1>Rust</h1>
<li><a href="/rust/collections">集合</a></li>
<li><a href="/rust/lifecycle">生命周期</a></li>
<li><a href="/rust/exception-handle">错误处理</a></li>
<li><a href="/rust/packages">包和模块</a></li>
<li><a href="/rust/rust-doc">注释和文档</a></li>
</ul>

</div>
Expand Down
2 changes: 1 addition & 1 deletion SpringCloud/bus/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ <h1>服务总线</h1>

<span class="tag">

<a href="/SpringCloud/bus" style="color: #ff7d73">服务总线</a>
<a href="/SpringCloud/bus" style="color: #00a596">服务总线</a>
</span>

</span>
Expand Down
2 changes: 1 addition & 1 deletion SpringCloud/bus/springcloud-bus.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ <h1>SpringCloud Bus</h1>

<span class="tag">

<a href="/SpringCloud/bus" style="color: #00a596">服务总线</a>
<a href="/SpringCloud/bus" style="color: #ffa2c4">服务总线</a>
</span>

</span>
Expand Down
2 changes: 1 addition & 1 deletion SpringCloud/config-center/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ <h1>配置中心</h1>

<span class="tag">

<a href="/SpringCloud/config-center" style="color: #ff7d73">配置中心</a>
<a href="/SpringCloud/config-center" style="color: #00bcd4">配置中心</a>
</span>

</span>
Expand Down
2 changes: 1 addition & 1 deletion SpringCloud/config-center/springcloud-config.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ <h1>SpringCloud Config</h1>

<span class="tag">

<a href="/SpringCloud/config-center" style="color: #00a596">配置中心</a>
<a href="/SpringCloud/config-center" style="color: #ffa2c4">配置中心</a>
</span>

</span>
Expand Down
2 changes: 1 addition & 1 deletion SpringCloud/gateway/springcloud-gateway.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ <h1>SpringCloud Gateway</h1>

<span class="tag">

<a href="/SpringCloud/gateway/" style="color: #00bcd4">服务网关</a>
<a href="/SpringCloud/gateway/" style="color: #00a596">服务网关</a>
</span>

</span>
Expand Down
2 changes: 1 addition & 1 deletion SpringCloud/service-degradation/hystrix.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ <h1>Hystrix</h1>

<span class="tag">

<a href="/SpringCloud/service-degradation" style="color: #00bcd4">服务降级</a>
<a href="/SpringCloud/service-degradation" style="color: #ffa2c4">服务降级</a>
</span>

</span>
Expand Down
2 changes: 1 addition & 1 deletion SpringCloud/service-degradation/sentinel.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ <h1>Sentinel</h1>

<span class="tag">

<a href="/SpringCloud/service-degradation" style="color: #00bcd4">服务降级</a>
<a href="/SpringCloud/service-degradation" style="color: #00a596">服务降级</a>
</span>

</span>
Expand Down
2 changes: 1 addition & 1 deletion SpringCloud/service-invoke/open-feign.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ <h1>OpenFeign</h1>

<span class="tag">

<a href="/SpringCloud/service-invoke" style="color: #00a596">服务调用</a>
<a href="/SpringCloud/service-invoke" style="color: #ff7d73">服务调用</a>
</span>

</span>
Expand Down
2 changes: 1 addition & 1 deletion SpringCloud/service-invoke/spring-cloud-square.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ <h1>Spring Cloud Square</h1>

<span class="tag">

<a href="/SpringCloud/service-invoke" style="color: #00a596">服务调用</a>
<a href="/SpringCloud/service-invoke" style="color: #ff7d73">服务调用</a>
</span>

</span>
Expand Down
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,8 @@ <h2 class="post-title">Rust</h2>
<li><a href="/rust/collections">集合</a></li>
<li><a href="/rust/lifecycle">生命周期</a></li>
<li><a href="/rust/exception-handle">错误处理</a></li>
<li><a href="/rust/packages">包和模块</a></li>
<li><a href="/rust/rust-doc">注释和文档</a></li>
</ul>


Expand Down
2 changes: 1 addition & 1 deletion java-source/concurrent-hashmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ <h1>ConcurrentHashMap源码</h1>

<span class="tag">

<a href="/2023/03/05/java-source#Java" style="color: #03a9f4">Java</a>
<a href="/2023/03/05/java-source#Java" style="color: #ffa2c4">Java</a>
</span>

</span>
Expand Down
2 changes: 1 addition & 1 deletion java-source/conditional.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ <h1>@Conditional注解</h1>

<span class="tag">

<a href="/2023/03/05/java-source#Spring-Boot" style="color: #00a596">SpringBoot</a>
<a href="/2023/03/05/java-source#Spring-Boot" style="color: #03a9f4">SpringBoot</a>
</span>

</span>
Expand Down
2 changes: 1 addition & 1 deletion java-source/hash-map.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ <h1>HashMap源码</h1>

<span class="tag">

<a href="/2023/03/05/java-source#Java" style="color: #ffa2c4">Java</a>
<a href="/2023/03/05/java-source#Java" style="color: #03a9f4">Java</a>
</span>

</span>
Expand Down
2 changes: 1 addition & 1 deletion java-source/linked-transfer-queue.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ <h1></h1>
<span class="icon">
<i class="fa-solid fa-calendar fa-fw"></i>
</span>
2024/3/25
2024/3/29
</span>


Expand Down
2 changes: 1 addition & 1 deletion java-source/named-context-factory.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ <h1>NamedContextFactory使用与源码解读</h1>

<span class="tag">

<a href="/2023/03/05/java-source#Spring-Cloud" style="color: #00bcd4">SpringCloud</a>
<a href="/2023/03/05/java-source#Spring-Cloud" style="color: #03a9f4">SpringCloud</a>
</span>

</span>
Expand Down
2 changes: 1 addition & 1 deletion java-source/springcloud-sentinel-source.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ <h1>SpringCloud Sentinel 排队等待和Warm Up限流源码</h1>

<span class="tag">

<a href="/2023/03/05/java-source#Spring-Cloud" style="color: #03a9f4">SpringCloud</a>
<a href="/2023/03/05/java-source#Spring-Cloud" style="color: #00bcd4">SpringCloud</a>
</span>

</span>
Expand Down
2 changes: 1 addition & 1 deletion java-source/synchronized.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ <h1>synchronized与锁升级</h1>

<span class="tag">

<a href="/2023/03/05/java-source#JVM" style="color: #ffa2c4">JVM</a>
<a href="/2023/03/05/java-source#JVM" style="color: #03a9f4">JVM</a>
</span>

</span>
Expand Down
2 changes: 1 addition & 1 deletion java-source/threadpool.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ <h1>线程池</h1>

<span class="tag">

<a href="/2023/03/05/java-source#Java" style="color: #03a9f4">Java</a>
<a href="/2023/03/05/java-source#Java" style="color: #00bcd4">Java</a>
</span>

</span>
Expand Down
139 changes: 137 additions & 2 deletions rust/packages.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ <h1>包和模块</h1>
</span>

<span class="category">
<a href="/2023/12/04/Rust/">
<a href="/2023/12/04/rust/">
<span class="icon">
<i class="fa-solid fa-bookmark fa-fw"></i>
</span>
Expand All @@ -191,7 +191,10 @@ <h1>包和模块</h1>

<toc-component></toc-component>
<div class="content" v-pre id="main-content">
<h1 id="Package-和-Crate"><a href="#Package-和-Crate" class="headerlink" title="Package 和 Crate"></a>Package 和 Crate</h1><blockquote>
<blockquote>
<p>这一章很抽象,一定要自己多写,不然很难理解。</p>
</blockquote>
<h1 id="Package-和-Crate"><a href="#Package-和-Crate" class="headerlink" title="Package 和 Crate"></a>Package 和 Crate</h1><blockquote>
<p>crate!我第一眼看成了 create…</p>
</blockquote>
<p><code>crate</code>(箱) 是 Rust 的最小编译单元,一个 <code>package</code> 中包含一个活多个 <code>crate</code><code>crate</code>可以是一个二进制项目,或者一个库。</p>
Expand Down Expand Up @@ -271,6 +274,138 @@ <h2 id="使用相对路径导入模块"><a href="#使用相对路径导入模块
<li><code>self</code> 类似于路径中的 <code>./</code></li>
<li><code>super</code> 类似路径中的 <code>../</code></li>
</ul>
<h2 id="使用-use-导入模块"><a href="#使用-use-导入模块" class="headerlink" title="使用 use 导入模块"></a>使用 use 导入模块</h2><p>可以使用 <code>use</code> 关键字来简化导入:</p>
<pre><code class="rust">// hosting.rs
use crate::product::provider;

pub fn add_to_waitlist() &#123;&#125;

pub fn seat_at_table() -&gt; String &#123;
provider::give()
&#125;
</code></pre>
<p><code>use</code> 也可以直接导入函数:</p>
<pre><code class="rust">// hosting.rs
use crate::product::provider::give;

pub fn add_to_waitlist() &#123;&#125;

pub fn seat_at_table() -&gt; String &#123;
give()
&#125;
</code></pre>
<h2 id="限制可见性语法"><a href="#限制可见性语法" class="headerlink" title="限制可见性语法"></a>限制可见性语法</h2><ul>
<li>pub 意味着可见性无任何限制</li>
<li>pub(crate) 表示在当前包可见</li>
<li>pub(self) 在当前模块可见</li>
<li>pub(super) 在父模块可见</li>
<li>pub(in <path>) 表示在某个路径代表的模块中可见,其中 path 必须是父模块或者祖先模块</li>
</ul>
<pre><code class="rust">// 一个名为 `my_mod` 的模块
mod my_mod &#123;
// 模块中的项默认具有私有的可见性
fn private_function() &#123;
println!(&quot;called `my_mod::private_function()`&quot;);
&#125;

// 使用 `pub` 修饰语来改变默认可见性。
pub fn function() &#123;
println!(&quot;called `my_mod::function()`&quot;);
&#125;

// 在同一模块中,项可以访问其它项,即使它是私有的。
pub fn indirect_access() &#123;
print!(&quot;called `my_mod::indirect_access()`, that\n&gt; &quot;);
private_function();
&#125;

// 模块也可以嵌套
pub mod nested &#123;
pub fn function() &#123;
println!(&quot;called `my_mod::nested::function()`&quot;);
&#125;

#[allow(dead_code)]
fn private_function() &#123;
println!(&quot;called `my_mod::nested::private_function()`&quot;);
&#125;

// 使用 `pub(in path)` 语法定义的函数只在给定的路径中可见。
// `path` 必须是父模块(parent module)或祖先模块(ancestor module)
pub(in crate::my_mod) fn public_function_in_my_mod() &#123;
print!(&quot;called `my_mod::nested::public_function_in_my_mod()`, that\n &gt; &quot;);
public_function_in_nested()
&#125;

// 使用 `pub(self)` 语法定义的函数则只在当前模块中可见。
pub(self) fn public_function_in_nested() &#123;
println!(&quot;called `my_mod::nested::public_function_in_nested&quot;);
&#125;

// 使用 `pub(super)` 语法定义的函数只在父模块中可见。
pub(super) fn public_function_in_super_mod() &#123;
println!(&quot;called my_mod::nested::public_function_in_super_mod&quot;);
&#125;
&#125;

pub fn call_public_function_in_my_mod() &#123;
print!(&quot;called `my_mod::call_public_funcion_in_my_mod()`, that\n&gt; &quot;);
nested::public_function_in_my_mod();
print!(&quot;&gt; &quot;);
nested::public_function_in_super_mod();
&#125;

// `pub(crate)` 使得函数只在当前包中可见
pub(crate) fn public_function_in_crate() &#123;
println!(&quot;called `my_mod::public_function_in_crate()&quot;);
&#125;

// 嵌套模块的可见性遵循相同的规则
mod private_nested &#123;
#[allow(dead_code)]
pub fn function() &#123;
println!(&quot;called `my_mod::private_nested::function()`&quot;);
&#125;
&#125;
&#125;

fn function() &#123;
println!(&quot;called `function()`&quot;);
&#125;

fn main() &#123;
// 模块机制消除了相同名字的项之间的歧义。
function();
my_mod::function();

// 公有项,包括嵌套模块内的,都可以在父模块外部访问。
my_mod::indirect_access();
my_mod::nested::function();
my_mod::call_public_function_in_my_mod();

// pub(crate) 项可以在同一个 crate 中的任何地方访问
my_mod::public_function_in_crate();

// pub(in path) 项只能在指定的模块中访问
// 报错!函数 `public_function_in_my_mod` 是私有的
//my_mod::nested::public_function_in_my_mod();
// 试一试 ^ 取消该行的注释

// 模块的私有项不能直接访问,即便它是嵌套在公有模块内部的

// 报错!`private_function` 是私有的
//my_mod::private_function();
// 试一试 ^ 取消此行注释

// 报错!`private_function` 是私有的
//my_mod::nested::private_function();
// 试一试 ^ 取消此行的注释

// 报错! `private_nested` 是私有的
//my_mod::private_nested::function();
// 试一试 ^ 取消此行的注释
&#125;
</code></pre>

</div>

Expand Down
Loading

0 comments on commit 22f24c4

Please sign in to comment.