# Rust

All Rust's integer types are compiled to LLVM integers (opens new window). The LLVM abstract machine allows integers of any bit width from 1 to 2^23 - 1.* LLVM instructions (opens new window) typically work on integers of any size.


Rust’s solution to this problem rests on the insight that futures are always safe to move when they are first created, and only become unsafe to move when they are polled.

From this , we can see that every future has two life stages

Starting after its first poll, we must assume the future may not be safe to move

To enter its second life stage, the future must be polled. The poll method requires the future be passed as a Pin<&mut Self> value. Pin is a wrapper for pointer types (like &mut Self) that restricts how the pointers can be used ensuring that their referents (like Self) cannot ever be moved again. So you must produce a Pin-wrapped pointer to the future before you can poll it.

Keep in mind that this move fragility is limited to futures of asynchronous functions and blocks, with their special compiler-generated Future implementations. If you implement Future by hand for your own types, as we did for our SpawnBlocking type in “Invoking Wakers: spawn_blocking”, such futures are perfectly safe to move both before and after they’ve been polled

few ways to get a pinned pointer to asynchronous function or block

Every way to obtain a pinned pointer to these futures entails giving up ownership of the future, and there is no way to get it back out.

so applying Box::pin to an asynchronous function or block future gives you a future you can use anywhere, at the cost of a heap allocation.

poll a future without give up ownership


PollFn 将同步函数封装成 Feature 用于异步函数中

custom future

PollFn


proc-macro

proc-macro


raw string


async

!ready

Syntactic sugar


table of PhantomData patterns


rust - Update / re-initialize a var defined in lazy_static - Stack Overflow (opens new window)


# Cargo

[[example]]
name = "example_name"
path = "path/to/example/main.rs"
1
2
3

cargo run --example example_name

# rust 切换到 nightly
rustup default nightly
1
# 切回到稳定版
rus
tup default stable
1
2