We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
书中为 pointer: NonZero<*const T>, 然而现有(Nightly 2020/1/9)实现已更改为:
pointer: NonZero<*const T>
#[rustc_layout_scalar_valid_range_start(1)] pub struct Unique<T: ?Sized> { pointer: *const T, _marker: PhantomData<T>, }
注意上文出现的 rustc_attr, 现在应该是靠这个保证非0从而进行优化。
类似的,现在 rust 提供了 core::ptr::NonNull:
#[rustc_layout_scalar_valid_range_start(1)] #[rustc_nonnull_optimization_guaranteed] pub struct NonNull<T: ?Sized> { pointer: *const T, }
也提供了通过宏统一加上 #[rustc_layout_scalar_valid_range_start(1)] 和 #[rustc_nonnull_optimization_guaranteed] 的一系列 core::num::NonZero{IntType} 可以保证非零。未来应该建议用户使用这些提供的非零指针 / 整型进行优化。 举例:let nonZeroA: NonZeroI64 = std::num::NonZeroI64::new(1).unwrap();
#[rustc_layout_scalar_valid_range_start(1)]
#[rustc_nonnull_optimization_guaranteed]
let nonZeroA: NonZeroI64 = std::num::NonZeroI64::new(1).unwrap();
查看 rustc commit history 后发现相关更改发生在:rust-lang/rust@7a09115
The text was updated successfully, but these errors were encountered:
是的! 你说的完全正确。
Sorry, something went wrong.
No branches or pull requests
书中为
pointer: NonZero<*const T>
, 然而现有(Nightly 2020/1/9)实现已更改为:注意上文出现的 rustc_attr, 现在应该是靠这个保证非0从而进行优化。
类似的,现在 rust 提供了 core::ptr::NonNull:
也提供了通过宏统一加上
#[rustc_layout_scalar_valid_range_start(1)]
和#[rustc_nonnull_optimization_guaranteed]
的一系列 core::num::NonZero{IntType} 可以保证非零。未来应该建议用户使用这些提供的非零指针 / 整型进行优化。举例:
let nonZeroA: NonZeroI64 = std::num::NonZeroI64::new(1).unwrap();
查看 rustc commit history 后发现相关更改发生在:rust-lang/rust@7a09115
The text was updated successfully, but these errors were encountered: