Comprehensive Rust(繁体中文) 202406block, and they are not accessed either through the // references or concurrently through any other pointers. unsafe { println!("r1 is: {}", *r1); *r1 = String::from("uhoh"); println!("r2 is: {}", *r2); of the unsafe operations it is doing. In the case of pointer dereferences, this means that the pointers must be valid, i.e.: • The pointer must be non-null. • The pointer must be dereferenceable (within 如果您的函式必須滿足特定條件才能避免未定義的行為,您可以將其標示為 unsafe。 /// Swaps the values pointed to by the given pointers. /// /// # Safety /// /// The pointers must be valid and properly aligned. unsafe fn swap(a: *mut u8, b: *mut u8) {0 码力 | 356 页 | 1.41 MB | 1 年前3
共 1 条
- 1













