-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #30916 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #30712, #30895, #30902, #30903, #30909, #30910, #30911, #30912, #30914 - Failed merges:
- Loading branch information
Showing
9 changed files
with
76 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
% Using Rust Without the Standard Library | ||
|
||
Rust’s standard library provides a lot of useful functionality, but assumes | ||
support for various features of its host system: threads, networking, heap | ||
allocation, and others. There are systems that do not have these features, | ||
however, and Rust can work with those too! To do so, we tell Rust that we | ||
don’t want to use the standard library via an attribute: `#![no_std]`. | ||
|
||
> Note: This feature is technically stable, but there are some caveats. For | ||
> one, you can build a `#![no_std]` _library_ on stable, but not a _binary_. | ||
> For details on binaries without the standard library, see [the nightly | ||
> chapter on `#![no_std]`](no-stdlib.html) | ||
To use `#![no_std]`, add a it to your crate root: | ||
|
||
```rust | ||
#![no_std] | ||
|
||
fn plus_one(x: i32) -> i32 { | ||
x + 1 | ||
} | ||
``` | ||
|
||
Much of the functionality that’s exposed in the standard library is also | ||
available via the [`core` crate](../core/). When we’re using the standard | ||
library, Rust automatically brings `std` into scope, allowing you to use | ||
its features without an explicit import. By the same token, when using | ||
`!#[no_std]`, Rust will bring `core` into scope for you, as well as [its | ||
prelude](../core/prelude/v1/). This means that a lot of code will Just Work: | ||
|
||
```rust | ||
#![no_std] | ||
|
||
fn may_fail(failure: bool) -> Result<(), &'static str> { | ||
if failure { | ||
Err("this didn’t work!") | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters