Skip to content

Commit

Permalink
Disambiguate try_into, add web to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpratt committed May 4, 2020
1 parent 66e1ba2 commit bf553fb
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
58 changes: 57 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,62 @@ jobs:
command: check
args: --no-default-features --features serde,rand --target thumbv7em-none-eabihf

check-web:
name: Type checking (web)
runs-on: ubuntu-latest
strategy:
matrix:
rust: [1.32.0, 1.36.0, stable] # 1.36 is when alloc was stabilized

steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install cargo-web
uses: actions-rs/install@v0.1
with:
crate: cargo-web
use-tool-cache: true

- name: Cache target
uses: actions/cache@v1
env:
cache-name: target
with:
path: ./target
key: ubuntu-latest-typecheck-target-${{ matrix.rust }}-web

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
target: wasm32-unknown-unknown
override: true

# ensure `#![no_std]` support
- name: Run `cargo web check --no-default-features`
uses: actions-rs/cargo@v1
with:
command: web
args: check --no-default-features
if: matrix.rust != '1.32.0' # alloc is unstable in 1.32

# `#![no_std]` with serde, rand
- name: Run `cargo web check --no-default-features --features serde,rand`
uses: actions-rs/cargo@v1
with:
command: web
args: check --no-default-features --features serde,rand
if: matrix.rust != '1.32.0' # alloc is unstable in 1.32

# everything
- name: Run `cargo check --features serde,deprecated,panicking-api,rand`
uses: actions-rs/cargo@v1
with:
command: check
args: --features serde,deprecated,panicking-api,rand

test:
name: Test suite
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -191,7 +247,7 @@ jobs:
name: Documentation
runs-on: ubuntu-latest
# ensure docs only get pushed if everything else is successful
needs: [check, test, fmt, clippy]
needs: [check, check-embedded, check-web, test, fmt, clippy]

steps:
- name: Checkout
Expand Down
6 changes: 2 additions & 4 deletions src/utc_offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use crate::{
internal_prelude::*,
};
use core::fmt::{self, Display};
#[cfg(cargo_web)]
use stdweb::js;

/// An offset from UTC.
///
Expand Down Expand Up @@ -490,7 +488,7 @@ fn try_local_offset_at(datetime: OffsetDateTime) -> Option<UtcOffset> {

diff_secs.try_into().ok().map(UtcOffset::seconds)
} else if #[cfg(cargo_web)] {
use stdweb::unstable::TryInto;
use stdweb::js;

let timestamp_utc = datetime.timestamp();
let low_bits = (timestamp_utc & 0xFF_FF_FF_FF) as i32;
Expand All @@ -502,7 +500,7 @@ fn try_local_offset_at(datetime: OffsetDateTime) -> Option<UtcOffset> {
.getTimezoneOffset() * -60;
};

timezone_offset.try_into().ok().map(UtcOffset::seconds)
stdweb::unstable::TryInto::try_into(timezone_offset).ok().map(UtcOffset::seconds)
} else {
None
}
Expand Down

0 comments on commit bf553fb

Please sign in to comment.