Merge pull request #1 from KaiserY/main

Update
pull/867/head
须语 2 months ago committed by GitHub
commit d61cfdeefa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -25,8 +25,8 @@ jobs:
- name: Install mdbook & mdbook-typst-pdf
run: |
mkdir bin
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.40/mdbook-v0.4.40-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
curl -sSL https://github.com/KaiserY/mdbook-typst-pdf/releases/download/v0.5.1/mdbook-typst-pdf-x86_64-unknown-linux-musl.tar.xz | tar -xJ --directory=bin --strip-components 1
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.49/mdbook-v0.4.49-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
curl -sSL https://github.com/KaiserY/mdbook-typst-pdf/releases/download/v0.6.2/mdbook-typst-pdf-x86_64-unknown-linux-musl.tar.xz | tar -xJ --directory=bin --strip-components 1
echo "$(pwd)/bin" >> ${GITHUB_PATH}
- name: Install font
run: |

@ -1,10 +1,11 @@
# Rust 程序设计语言2021 edition简体中文版
# Rust 程序设计语言2024 edition简体中文版
![Build Status](https://github.com/KaiserY/trpl-zh-cn/workflows/CI/badge.svg)
## 状态
- 新增 ch17 async & await 施工中
- ch17 async & await 施工完毕。
- 2024 edtion 施工中,若示例代码有误请见谅。
PS:
@ -15,7 +16,7 @@ PS:
## 校对
部分翻译采用 ChatGPT 4o 进行翻译校对。提示词详见 [proofreading_prompt.md](proofreading_prompt.md)
部分章节采用 ChatGPT o4-mini 进行翻译校对。提示词详见 [proofreading_prompt.md](proofreading_prompt.md)
## 静态页面构建与文档撰写

@ -21,6 +21,7 @@ edit-url-template = "https://github.com/KaiserY/trpl-zh-cn/edit/main/{path}"
[output.typst-pdf]
pdf = true
section-number = true
rust-book = true
[rust]
edition = "2021"

@ -42,4 +42,26 @@ body.ayu .not_desired_behavior {
.ferris-explain {
width: 100px;
}
}
/*
A bit of a hack to make small Ferris use the existing buttons container but
only show/hide the buttons on hover over the `pre`. Targeting `.listing`
increases the specificity of this rule.
*/
pre > .buttons {
visibility: visible;
opacity: 1;
transition: none;
}
pre > .buttons button {
visibility: hidden;
opacity: 0;
transition: visibility 0.1s linear, opacity 0.1s linear;
}
pre:hover > .buttons button {
visibility: visible;
opacity: 1;
}

@ -1,65 +1,102 @@
var ferrisTypes = [
// @ts-check
/**
* @typedef {{ attr: string, title: string }} FerrisType
*/
/** @type {Array<FerrisType>} */
const FERRIS_TYPES = [
{
attr: 'does_not_compile',
title: '这段代码无法通过编译!'
attr: "does_not_compile",
title: "This code does not compile!",
},
{
attr: 'panics',
title: '这段代码会 Panic'
attr: "panics",
title: "This code panics!",
},
{
attr: 'not_desired_behavior',
title: '这段代码的运行结果不符合预期。'
}
]
attr: "not_desired_behavior",
title: "This code does not produce the desired behavior.",
},
];
document.addEventListener('DOMContentLoaded', () => {
for (var ferrisType of ferrisTypes) {
attachFerrises(ferrisType)
document.addEventListener("DOMContentLoaded", () => {
for (let ferrisType of FERRIS_TYPES) {
attachFerrises(ferrisType);
}
})
});
/**
* @param {FerrisType} type
*/
function attachFerrises(type) {
var elements = document.getElementsByClassName(type.attr)
let elements = document.getElementsByClassName(type.attr);
for (var codeBlock of elements) {
var lines = codeBlock.innerText.replace(/\n$/, '').split(/\n/).length
var size = 'large'
if (lines < 4) {
size = 'small'
for (let codeBlock of elements) {
// Skip SVG etc.: in principle, these should never be attached to those, but
// this means if someone happens to have a browser extension which *is*
// attaching them, it will not break the code.
if (!(codeBlock instanceof HTMLElement)) {
continue;
}
var container = prepareFerrisContainer(codeBlock, size == 'small')
container.appendChild(createFerris(type, size))
let codeLines = codeBlock.innerText;
let extra = codeLines.endsWith("\n") ? 1 : 0;
let numLines = codeLines.split("\n").length - extra;
/** @type {'small' | 'large'} */
let size = numLines < 4 ? "small" : "large";
let container = prepareFerrisContainer(codeBlock, size == "small");
if (!container) {
continue;
}
container.appendChild(createFerris(type, size));
}
}
/**
* @param {HTMLElement} element - Code block element to attach a Ferris to.
* @param {boolean} useButtons - Whether to attach to existing buttons.
* @returns {Element | null} - The container element to use.
*/
function prepareFerrisContainer(element, useButtons) {
var foundButtons = element.parentElement.querySelector('.buttons')
let foundButtons = element.parentElement?.querySelector(".buttons");
if (useButtons && foundButtons) {
return foundButtons
return foundButtons;
}
var div = document.createElement('div')
div.classList.add('ferris-container')
let div = document.createElement("div");
div.classList.add("ferris-container");
element.parentElement.insertBefore(div, element)
if (!element.parentElement) {
console.error(`Could not install Ferris on ${element}, which is missing a parent`);
return null;
}
return div
element.parentElement.insertBefore(div, element);
return div;
}
/**
* @param {FerrisType} type
* @param {'small' | 'large'} size
* @returns {HTMLAnchorElement} - The generated anchor element.
*/
function createFerris(type, size) {
var a = document.createElement('a')
a.setAttribute('href', 'ch00-00-introduction.html#ferris')
a.setAttribute('target', '_blank')
let a = document.createElement("a");
a.setAttribute("href", "ch00-00-introduction.html#ferris");
a.setAttribute("target", "_blank");
var img = document.createElement('img')
img.setAttribute('src', 'img/ferris/' + type.attr + '.svg')
img.setAttribute('title', type.title)
img.classList.add('ferris')
img.classList.add('ferris-' + size)
let img = document.createElement("img");
img.setAttribute("src", "img/ferris/" + type.attr + ".svg");
img.setAttribute("title", type.title);
img.classList.add("ferris");
img.classList.add("ferris-" + size);
a.appendChild(img)
a.appendChild(img);
return a
}
return a;
}

@ -1,7 +1,7 @@
[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"
edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

@ -25,7 +25,7 @@ fn main() {
// ANCHOR_END: expect
// ANCHOR: print_guess
println!("You guessed: {}", guess);
println!("You guessed: {guess}");
// ANCHOR_END: print_guess
}
// ANCHOR: all

@ -1,6 +1,12 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
version = 4
[[package]]
name = "byteorder"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "cfg-if"
@ -10,9 +16,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "getrandom"
version = "0.2.12"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5"
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
dependencies = [
"cfg-if",
"libc",
@ -28,15 +34,36 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.153"
version = "0.2.170"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828"
[[package]]
name = "ppv-lite86"
version = "0.2.17"
version = "0.2.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04"
dependencies = [
"zerocopy",
]
[[package]]
name = "proc-macro2"
version = "1.0.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
@ -68,8 +95,46 @@ dependencies = [
"getrandom",
]
[[package]]
name = "syn"
version = "2.0.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00e2473a93778eb0bad35909dff6a10d28e63f792f16ed15e404fca9d5eeedbe"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "zerocopy"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
dependencies = [
"byteorder",
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]

@ -1,7 +1,7 @@
[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"
edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

@ -1,7 +1,7 @@
[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"
edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

@ -1,5 +1,6 @@
// ANCHOR: all
use std::io;
// ANCHOR: ch07-04
use rand::Rng;

@ -1,7 +1,7 @@
[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"
edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

@ -1,10 +1,4 @@
$ cargo build
Downloading crates ...
Downloaded rand_core v0.6.2
Downloaded getrandom v0.2.2
Downloaded rand_chacha v0.3.0
Downloaded ppv-lite86 v0.2.10
Downloaded libc v0.2.86
Compiling libc v0.2.86
Compiling getrandom v0.2.2
Compiling cfg-if v1.0.0
@ -14,9 +8,9 @@ $ cargo build
Compiling rand v0.8.5
Compiling guessing_game v0.1.0 (file:///projects/guessing_game)
error[E0308]: mismatched types
--> src/main.rs:22:21
--> src/main.rs:23:21
|
22 | match guess.cmp(&secret_number) {
23 | match guess.cmp(&secret_number) {
| --- ^^^^^^^^^^^^^^ expected `&String`, found `&{integer}`
| |
| arguments to this method are incorrect
@ -24,7 +18,7 @@ error[E0308]: mismatched types
= note: expected reference `&String`
found reference `&{integer}`
note: method defined here
--> /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/cmp.rs:839:8
--> /rustc/4eb161250e340c8f48f66e2b929ef4a5bed7c181/library/core/src/cmp.rs:964:8
For more information about this error, try `rustc --explain E0308`.
error: could not compile `guessing_game` (bin "guessing_game") due to 1 previous error

@ -1,8 +1,9 @@
// ANCHOR: here
use rand::Rng;
use std::cmp::Ordering;
use std::io;
use rand::Rng;
fn main() {
// --snip--
// ANCHOR_END: here

@ -1,7 +1,7 @@
[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"
edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

@ -1,7 +1,8 @@
use rand::Rng;
use std::cmp::Ordering;
use std::io;
use rand::Rng;
fn main() {
println!("Guess the number!");

@ -1,7 +1,7 @@
[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"
edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

@ -1,7 +1,8 @@
use rand::Rng;
use std::cmp::Ordering;
use std::io;
use rand::Rng;
fn main() {
println!("Guess the number!");

@ -1,8 +1,6 @@
[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
edition = "2024"
[dependencies]

@ -1,5 +1,5 @@
$ cargo run
Compiling guessing_game v0.1.0 (file:///projects/guessing_game)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.50s
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.08s
Running `target/debug/guessing_game`
Hello, world!

@ -1,7 +1,7 @@
[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"
edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

@ -1,7 +1,7 @@
[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"
edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

@ -1,7 +1,8 @@
use rand::Rng;
use std::cmp::Ordering;
use std::io;
use rand::Rng;
fn main() {
println!("Guess the number!");

@ -1,7 +1,7 @@
[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"
edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

@ -1,7 +1,8 @@
use rand::Rng;
use std::cmp::Ordering;
use std::io;
use rand::Rng;
fn main() {
println!("Guess the number!");

@ -1,7 +1,7 @@
[package]
name = "guessing_game"
version = "0.1.0"
edition = "2021"
edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

@ -1,7 +1,8 @@
use rand::Rng;
use std::cmp::Ordering;
use std::io;
use rand::Rng;
fn main() {
println!("Guess the number!");

@ -1,6 +1,6 @@
[package]
name = "functions"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "branches"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "loops"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "loops"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "loops"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "variables"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "variables"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "variables"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "variables"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "variables"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "floating-point"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "numeric-operations"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "boolean"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "char"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "tuples"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "tuples"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "tuples"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "arrays"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "arrays"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "arrays"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "functions"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "functions"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "functions"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "functions"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "functions"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "functions"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "functions"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "functions"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "comments"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,3 +1,3 @@
fn main() {
let lucky_number = 7; // Im feeling lucky today
let lucky_number = 7; // I'm feeling lucky today
}

@ -1,6 +1,6 @@
[package]
name = "comments"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,4 +1,4 @@
fn main() {
// Im feeling lucky today
// I'm feeling lucky today
let lucky_number = 7;
}

@ -1,6 +1,6 @@
[package]
name = "branches"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "branches"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "branches"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "branches"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "branches"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "branches"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "loops"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "loops"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "loops"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "loops"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,7 +1,7 @@
[package]
name = "no_type_annotations"
version = "0.1.0"
edition = "2021"
edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -6,4 +6,4 @@ fn main() {
// 使用 s
} // 此作用域已结束s 不再有效
// ANCHOR_END: here
}
}

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -8,7 +8,7 @@ fn main() {
makes_copy(x); // x 应该移动函数里,
// 但 i32 是 Copy 的,
// 所以在后面可继续使用 x
println!("{}", x); // 所以在后面可继续使用 x
} // 这里x 先移出了作用域,然后是 s。但因为 s 的值已被移走,
// 没有特殊之处

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,29 +1,30 @@
fn main() {
let s1 = gives_ownership(); // gives_ownership 将返回值
// 转移给 s1
let s1 = gives_ownership(); // gives_ownership moves its return
// value into s1
let s2 = String::from("hello"); // s2 进入作用域
let s2 = String::from("hello"); // s2 comes into scope
let s3 = takes_and_gives_back(s2); // s2 被移动到
// takes_and_gives_back 中,
// 它也将返回值移给 s3
} // 这里s3 移出作用域并被丢弃。s2 也移出作用域,但已被移走,
// 所以什么也不会发生。s1 离开作用域并被丢弃
let s3 = takes_and_gives_back(s2); // s2 is moved into
// takes_and_gives_back, which also
// moves its return value into s3
} // Here, s3 goes out of scope and is dropped. s2 was moved, so nothing
// happens. s1 goes out of scope and is dropped.
fn gives_ownership() -> String { // gives_ownership 会将
// 返回值移动给
// 调用它的函数
fn gives_ownership() -> String { // gives_ownership will move its
// return value into the function
// that calls it
let some_string = String::from("yours"); // some_string 进入作用域。
let some_string = String::from("yours"); // some_string comes into scope
some_string // 返回 some_string
// 并移出给调用的函数
//
some_string // some_string is returned and
// moves out to the calling
// function
}
// takes_and_gives_back 将传入字符串并返回该值
fn takes_and_gives_back(a_string: String) -> String { // a_string 进入作用域
//
// 该函数将传入字符串并返回该值
fn takes_and_gives_back(a_string: String) -> String {
// a_string comes into
// scope
a_string // 返回 a_string 并移出给调用的函数
}

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

@ -1,6 +1,6 @@
[package]
name = "ownership"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save