The Rust Programming Language,2nd EditionRust. In this chapter we’ll talk about ownership as well as several related features: borrowing, slices, and how Rust lays data out in memory. 4.1 What Is Ownership? Rust’s central feature is ownership Next, we’ll look at a different kind of reference: slices. 99 4.3 Slices Another data type that does not have ownership is the slice. Slices let you reference a contiguous sequence of elements in around that need to be kept in sync. Luckily, Rust has a solution to this problem: string slices. String Slices A string slice is a reference to part of a String, and looks like this: let s = String::from("hello0 码力 | 617 页 | 1.54 MB | 1 年前3
Comprehensive Rust(English) 20241248 9.2 Exclusive References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 9.3 Slices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 9.4 Strings . array is part of its type, which means that [u8; 3] and [u8; 4] are considered two different types. Slices, which have a size determined at runtime, are covered later. • Try accessing an out-of-bounds array minutes. It contains: Slide Duration Shared References 10 minutes Exclusive References 10 minutes Slices 10 minutes Strings 10 minutes Exercise: Geometry 15 minutes 9.1 Shared References A reference provides0 码力 | 382 页 | 1.00 MB | 11 月前3
Comprehensive Rust ?46 9.2 Exclusive References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 9.3 Slices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 9.4 Strings . array is part of its type, which means that [u8; 3] and [u8; 4] are considered two different types. Slices, which have a size determined at runtime, are covered later. • Try accessing an out-of-bounds array minutes. It contains: Slide Duration Shared References 10 minutes Exclusive References 10 minutes Slices: &[T] 10 minutes Strings 10 minutes Exercise: Geometry 15 minutes 9.1 Shared References A reference0 码力 | 378 页 | 1009.46 KB | 1 年前3
2021-11-22 - Rust CTCFT - Rust for LinuxPadding: current solution, punting to developer /// Specifies that a type is safely writable to byte slices. /// /// This means that we don't read undefined values (which leads to UB) in preparation for writing byte slice. It also ensures that no potentially sensitive information is leaked into the /// byte slices. /// /// # Safety /// /// A type must not include padding bytes and must be fully initialised to current solution /// Specifies that a type is safely readable from byte slices. /// /// Not all types can be safely read from byte slices; examples from ///0 码力 | 53 页 | 332.50 KB | 9 月前3
Comprehensive Rust(Español) 20241249 9.2 Referencias exclusivas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 9.3 Slices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 9.4 Cadenas de _parte de su tipo), lo que significa que [u8; 3] y [u8; 4] se consideran dos tipos diferentes. Los slices, que tienen un tamaño determinado al tiempo de ejecución, serán discutidos mas tarde. • Prueba a Contiene: Diapositiva Duración Enums compartidas 10 minutos Referencias exclusivas 10 minutos Slices: &[T] 10 minutos Cadenas de texto (Strings) 10 minutos Ejercicio: geometría 15 minutos 9.1 Enums0 码力 | 389 页 | 1.04 MB | 11 月前3
Comprehensive Rust(Português do Brasil) 20241249 9.2 Referências Exclusivas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 9.3 Slices (Fatias) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 9.4 Strings . parte do seu tipo, o que significa que [u8; 3] e [u8; 4] são considerados dois tipos diferentes. Slices (fatias), que têm um tamanho determinado em tempo de execução, são abordados mais tarde. • Tente contains: Slide Duration Referências Compartilhadas 10 minutes Referências Exclusivas 10 minutes Slices: &[T] 10 minutes Strings 10 minutes Exercício: Geometria 15 minutes 9.1 Referências Compartilhadas0 码力 | 389 页 | 1.05 MB | 11 月前3
Comprehensive Rust(简体中文) 202412array is part of its type, which means that [u8; 3] and [u8; 4] are considered two different types. Slices, which have a size determined at runtime, are covered later. • 请尝试访问出界数组元素。系统会在运行时检查数组访问。Rust 通常会通过优化消除这些检查,以 segment should take about 55 minutes. It contains: Slide Duration 共享引用 10 minutes 独占引用 10 minutes Slices: &[T] 10 minutes 字符串 10 minutes 练习:几何图形 15 minutes 9.1 共享引用 引用提供了一种可以访问另一个值但无需对该值负责的方式,也被称为“借用”。共享引用处于只读状态, (&[i32]) no longer mentions the array length. This allows us to perform computation on slices of different sizes. • Slices always borrow from another object. In this example, a has to remain 'alive' (in scope)0 码力 | 359 页 | 1.33 MB | 11 月前3
Comprehensive Rust(한국어) 202412array is part of its type, which means that [u8; 3] and [u8; 4] are considered two different types. Slices, which have a size determined at runtime, are covered later. • 범위를 벗어난 배열 요소에 액세스해 보세요. 배열 액세스는 인덱스로 접근할 수있습니다. 하지만 범위를 벗어나면 패닉이 발생합니 다. 대신 get 을 사용하면 Option 을 반환합니다. pop 함수는 마지막 요소를 제거합니다. • Slices are covered on day 3. For now, students only need to know that a value of type Vec gives access to 제 23 장 수명 This segment should take about 1 hour and 10 minutes. It contains: Slide Duration Slices: &[T] 10 minutes 허상 (dangling) 참조 10 minutes 함수 호출에서의 수명 10 minutes 수명 5 minutes 수명 5 minutes 연습문제:0 码力 | 369 页 | 1.29 MB | 11 月前3
Comprehensive Rustarray is part of its type, which means that [u8; 3] and [u8; 4] are considered two different types. Slices, which have a size determined at runtime, are covered later. • 범위를 벗어난 배열 요소에 액세스해 보세요. 배열 액세스는 인덱스로 접근할 수있습니다. 하지만 범위를 벗어나면 패닉이 발생합니 다. 대신 get 을 사용하면 Option 을 반환합니다. pop 함수는 마지막 요소를 제거합니다. • Slices are covered on day 3. For now, students only need to know that a value of type Vec gives access to 제 23 장 수명 This segment should take about 1 hour and 10 minutes. It contains: Slide Duration Slices: &[T] 10 minutes 허상 (dangling) 참조 10 minutes 함수 호출에서의 수명 10 minutes 수명 5 minutes 수명 5 minutes 연습문제:0 码力 | 368 页 | 1.29 MB | 1 年前3
Comprehensive Rust(繁体中文)array is part of its type, which means that [u8; 3] and [u8; 4] are considered two different types. Slices, which have a size determined at runtime, are covered later. • 請嘗試存取超出範圍的陣列元素。系統會在執行階段檢查存取陣列的行為。Rust 23 部分 生命週期 This segment should take about 1 hour and 10 minutes. It contains: Slide Duration Slices: &[T] 10 minutes 迷途參照 10 minutes 函式呼叫中的生命週期 10 minutes 生命週期 5 minutes 生命週期 5 minutes 練習:Protobuf 因此,為了輕鬆建立完整陣列的切片,我們可以使用 &a[..]。 • s 是對 i32s 切片的參照。請注意,s (&[i32]) 的型別不再提及陣列長度,這有利於我們對不同大 小的切片執行運算。 126 • Slices always borrow from another object. In this example, a has to remain 'alive' (in scope) for at least0 码力 | 358 页 | 1.41 MB | 11 月前3
共 15 条
- 1
- 2













