Use AtomicU32 in RouteId (#616)

This commit is contained in:
Kai Jewson 2021-12-12 14:19:30 +00:00 committed by GitHub
parent b7cc3d4645
commit 9ed18d92cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 7 deletions

View file

@ -146,3 +146,24 @@ jobs:
with:
command: check ${{ matrix.checks }}
arguments: --all-features --manifest-path axum/Cargo.toml
armv5te-unknown-linux-musleabi:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: armv5te-unknown-linux-musleabi
override: true
profile: minimal
- uses: Swatinem/rust-cache@v1
- name: Check
uses: actions-rs/cargo@v1
env:
# Clang has native cross-compilation support
CC: clang
with:
command: check
args: --all --all-targets --all-features --target armv5te-unknown-linux-musleabi

View file

@ -52,7 +52,7 @@ tokio-tungstenite = { optional = true, version = "0.16" }
[dev-dependencies]
futures = "0.3"
reqwest = { version = "0.11", features = ["json", "stream"] }
reqwest = { version = "0.11", default-features = false, features = ["json", "stream"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.6.1", features = ["macros", "rt", "rt-multi-thread", "net"] }

View file

@ -48,13 +48,18 @@ pub use self::method_routing::{
};
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
struct RouteId(u64);
struct RouteId(u32);
impl RouteId {
fn next() -> Self {
use std::sync::atomic::{AtomicU64, Ordering};
static ID: AtomicU64 = AtomicU64::new(0);
Self(ID.fetch_add(1, Ordering::SeqCst))
use std::sync::atomic::{AtomicU32, Ordering};
// `AtomicU64` isn't supported on all platforms
static ID: AtomicU32 = AtomicU32::new(0);
let id = ID.fetch_add(1, Ordering::Relaxed);
if id == u32::MAX {
panic!("Over `u32::MAX` routes created. If you need this, please file an issue.");
}
Self(id)
}
}

View file

@ -93,7 +93,7 @@ async fn authorize(Json(payload): Json<AuthPayload>) -> Result<Json<AuthBody>, A
let claims = Claims {
sub: "b@b.com".to_owned(),
company: "ACME".to_owned(),
exp: 10000000000,
exp: 100000,
};
// Create the authorization token
let token = encode(&Header::default(), &claims, &KEYS.encoding)

View file

@ -12,5 +12,6 @@ tracing-subscriber = { version="0.3", features = ["env-filter"] }
oauth2 = "4.1"
async-session = "3.0.0"
serde = { version = "1.0", features = ["derive"] }
reqwest = { version = "0.11", features = ["json"] }
# Use Rustls because it makes it easier to cross-compile on CI
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls", "json"] }
headers = "0.3"