How can I import a crate, which uses unstable features

I have a crate which uses some unstable features(auto trait, partial specialization), but I guarantee that all the unstable features are sealed well, how can I import it from a project which use a stable toolchains? And furthermore, if it is possible to mix stable and unstable crate in a project, is it allowed to publish this crate to crate.io?

You mean unstable API from the standard library? (My subsequent answers only make sense if this is the case.)

If any dependency of your crate uses unstable #[feature(…)], then your crate also only works with a nightly compiler.

There is no way to seal the fact that compilation might break in future Rust versions.

There’s no requirements at all on crates published to crates.io. You can publish anything you want, including code that only works on current nightly compiler or code that doesn’t compile at all. Since docs.rs uses nightly compilers for documentation, you’ll even get working docs.rs-documentation when publishing nightly-only crates.

2 Likes

I'm so sorry, I mean unstable features, not unstable APIs (like auto trait, partial specialization...), I changed the question to make myself clear, but according to you answer, the answer of the modified question is still a No, right?

I came up with an idea that I can prebuild my crate with nightly tool chain, but I didn't find any resource saying a crate can contain a static library (.a)

There are some tension between people who are trying to do what you are trying to do and Rust developers.
Of course Rust developers, themselves, use that ability and Firefox does that, too, but be prepared to fight really hard when tricks you use for this would break.

I would strongly advise against that. If you need nightly features then just use nightly compiler.
And since you have to explicitly enable features before you may use them there are no chance to accidentally use them without noticing.

2 Likes

Hi, do you suggest that some products (for example Firefox) already published with nightly toolchain built, it's not that rare to build projects with nightly, as long as the price can be paid?

One of the most popular crates out, there, rocket.rs, still haven't made stable-compatible release.
After years of development (they have stable-compatible release-candidate, though).
So using nightly-only crates and nightly-only compiler is Ok.
Doing what you are trying to do and hide instability in you crate is not something you are supposed to do.

You can read about reasoning here.

3 Likes

You convinced me, I'll focus on what I'm doing, not concerning the stable/unstable problem :+1:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.