 Rust 程序设计语言 简体中文版 1.85.0一路跟过来的,必须手动将之后例子的代码放入一个 main 函数中。这样,例子将显得更加简 明,使我们可以关注实际细节而不是样板代码。 在所有权的第一个例子中,我们看看一些变量的 作用域(scope)。作用域是一个项(item) 在程序中有效的范围。假设有这样一个变量: let s = "hello"; 变量 s 绑定到了一个字符串字面值,这个字符串值是硬编码进程序代码中的。这个变量从声明 的点开始直到当前作用域结束时都是有效的。示例 量离开作用域,Rust 为我们调用一个特殊的函数。这个函数叫做 drop,在这里 String 的作 者可以放置释放内存的代码。Rust 在结尾的 } 处自动调用 drop。 注意:在 C++ 中,这种 item 在生命周期结束时释放资源的模式有时被称作 资源获取 即初始化(Resource Acquisition Is Initialization (RAII))。如果你使用过 RAII 模式的 话应该对 first_word(s: &String) -> usize { let bytes = s.as_bytes(); for (i, &item) in bytes.iter().enumerate() { if item == b' ' { return i; } } s.len() } 示例 4-7:first_word0 码力 | 562 页 | 3.23 MB | 25 天前3 Rust 程序设计语言 简体中文版 1.85.0一路跟过来的,必须手动将之后例子的代码放入一个 main 函数中。这样,例子将显得更加简 明,使我们可以关注实际细节而不是样板代码。 在所有权的第一个例子中,我们看看一些变量的 作用域(scope)。作用域是一个项(item) 在程序中有效的范围。假设有这样一个变量: let s = "hello"; 变量 s 绑定到了一个字符串字面值,这个字符串值是硬编码进程序代码中的。这个变量从声明 的点开始直到当前作用域结束时都是有效的。示例 量离开作用域,Rust 为我们调用一个特殊的函数。这个函数叫做 drop,在这里 String 的作 者可以放置释放内存的代码。Rust 在结尾的 } 处自动调用 drop。 注意:在 C++ 中,这种 item 在生命周期结束时释放资源的模式有时被称作 资源获取 即初始化(Resource Acquisition Is Initialization (RAII))。如果你使用过 RAII 模式的 话应该对 first_word(s: &String) -> usize { let bytes = s.as_bytes(); for (i, &item) in bytes.iter().enumerate() { if item == b' ' { return i; } } s.len() } 示例 4-7:first_word0 码力 | 562 页 | 3.23 MB | 25 天前3
 Tornado 6.5 DocumentationQueue.get pauses until there is an item in the queue. If the queue has a maximum size set, a coroutine that yields Queue.put pauses until there is room for another item. A Queue maintains a count of unfinished markup: Tornado 6.5 DocumentationQueue.get pauses until there is an item in the queue. If the queue has a maximum size set, a coroutine that yields Queue.put pauses until there is room for another item. A Queue maintains a count of unfinished markup:- {{ title }} - 
{% for item in items %}
- {{ escape(item) }} {% end %}
 0 码力 | 272 页 | 1.12 MB | 3 月前3
 Tornado 6.5 DocumentationQueue.get pauses until there is an item in the queue. If the queue has a maximum size set, a coroutine that yields Queue.put pauses until there is room for another item. A Queue maintains a count of unfinished Tornado 6.5 DocumentationQueue.get pauses until there is an item in the queue. If the queue has a maximum size set, a coroutine that yields Queue.put pauses until there is room for another item. A Queue maintains a count of unfinished- {{ title }} -  
      {% for item in items %} 
        
- {{ escape(item) }} {% end %}
 














