Rust 1.41.0版本:FFI中Box 的新保证,货物安装的改进,特征的宽松

Rust团队很高兴地宣布发布新版本1.41.0。Rust是一种编程语言,它使每个人都可以创建可靠而高效的软件。


如果您使用tools安装了rustup版本的Rust ,那么要升级到1.41.0版本,您只需要运行以下命令:


rustup update stable

如果您尚未安装它rustup,您可以安装它从我们的网站的相应页面,也可以查看详细的发行说明在GitHub上。


稳定版1.41.0中包含什么


Rust 1.41.0的主要创新是放宽了对特征实施的限制,改进cargo install,新的文件格式Cargo.lock更易于使用git以及为Box<T>与FFI相关的文件提供了新的保证有关更多信息,请参见发行说明。


放宽对特质实施的限制


为了防止生态系统崩溃,当依赖项添加新的特征实现时,Rust使用孤立规则最重要的是,只有在实现该类型的类型或类型是本地类型的情况下才允许该类型实现。在当前箱子中定义。但是,使用归纳法则非常复杂


在Rust 1.41.0之前,此规则过于严格,会影响合成。例如,假设您的包实现了一个结构,BetterVec<T>并且您希望能够将其转换Vec<T>为标准库中的结构。您将编写以下代码:


impl<T> From<BetterVec<T>> for Vec<T> {
    // ...
}

...这是一个模式示例:


impl<T> ForeignTrait<LocalType> for ForeignType<T> {
    // ...
}

Rust 1.40.0 impl , From Vec , . , newtype, .


From Vec , ( From) . , Rust 1.41.0 impl.


RFC.


cargo install


cargo install . CLI-, Rust.


Rust 1.41.0, cargo install , . --force, .


Cargo.lock


, Cargo Cargo.lock, . , .


Rust 1.41.0 , . lock-, . , , PR, .


Box<T> FFI


Rust 1.41.0, , Box<T>, T: Sized, ABI C (T*). , extern "C" Rust C, Rust Box<T> - T, T* C. , C :


// C header */

//     
struct Foo* foo_new(void);

//     ; no-op   NULL.
void foo_delete(struct Foo*);

… Rust :


#[repr(C)]
pub struct Foo;

#[no_mangle]
pub extern "C" fn foo_new() -> Box<Foo> {
    Box::new(Foo)
}

//   NULL    `Option<_>`.
#[no_mangle]
pub extern "C" fn foo_delete(_: Option<Box<Foo>>) {}

, , Box<T> T* ABI, Box<T> -null, . , — Box', .


: Box<T> , C, Rust. C. Box<T>, C T* .


, Box<T>.



Rust 1.41.0, :



32- Apple


Rust 1.41.0 32- Apple, i686-apple-darwin. Rust 1.42.0 .


.



, Cargo Clippy . MIR, : "Inside Rust".


1.41.0


, Rust 1.41.0. , !



Rust - .


andreevlex, blandger, funkill, P0lunin nlinker.

Source: https://habr.com/ru/post/undefined/


All Articles