Skip to content

Commit

Permalink
Update everything and add CI
Browse files Browse the repository at this point in the history
  • Loading branch information
djkoloski committed Aug 11, 2024
1 parent 01df7a9 commit 777d1ce
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 96 deletions.
4 changes: 4 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[build]
rustdocflags = ["--cfg", "docsrs"]

[env]
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: rkyv
143 changes: 143 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
name: CI

on:
push:
pull_request:
workflow_dispatch:
schedule:
- cron: "0 10 * * *"

permissions:
contents: read

env:
RUSTFLAGS: -Dwarnings

jobs:
features:
name: Features / ${{ matrix.std }} ${{ matrix.derive }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
bytecheck:
- ''
- bytecheck

steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo test --verbose --tests --no-default-features --features "${{ matrix.bytecheck }}"

toolchain:
name: Toolchain / ${{ matrix.toolchain }} ${{ matrix.opt }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
toolchain:
- stable
- beta
- nightly
opt:
- ''
- --release

steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.toolchain }}
- run: cargo test --verbose ${{ matrix.opt }}

miri:
name: Miri / ${{ matrix.opt }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
opt:
- ''
- --release

steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@miri
- run: cargo miri setup
- run: cargo miri test ${{ matrix.opt }} --verbose
env:
MIRIFLAGS: -Zmiri-disable-stacked-borrows -Zmiri-tree-borrows

test:
name: Test / ${{ matrix.target }} ${{ matrix.opt }}
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
opt:
- ''
- --release
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: macos-latest
target: aarch64-apple-darwin
- os: windows-latest
target: x86_64-pc-windows-msvc

steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo test ${{ matrix.opt }}

cross:
name: Cross / ${{ matrix.target }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
target:
- i686-unknown-linux-gnu
- i586-unknown-linux-gnu
- armv7-unknown-linux-gnueabihf
- aarch64-unknown-linux-gnu
- thumbv6m-none-eabi

steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo install cross
- run: cross build --no-default-features --features "bytecheck" --target ${{ matrix.target }} --verbose

format:
name: Format
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- run: cargo fmt --check

clippy:
name: Clippy
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
components: clippy
- run: cargo clippy

doc:
name: Doc
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- run: cargo doc
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[package]
name = "rend"
description = "Cross-platform, endian-aware primitives for Rust"
version = "0.5.0-alpha.7"
authors = ["David Koloski <djkoloski@gmail.com>"]
edition = "2021"
description = "Endian-aware primitives for Rust"
license = "MIT"
documentation = "https://docs.rs/rend"
readme = "README.md"
repository = "https://github.com/djkoloski/rend"
keywords = ["endian", "no_std"]
categories = ["encoding", "no-std"]
readme = "crates-io.md"
documentation = "https://docs.rs/rend"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
# rend &emsp; [![Latest Version]][crates.io] [![License]][license path]
# `rend`

[Latest Version]: https://img.shields.io/crates/v/rend.svg
[![crates.io badge]][crates.io] [![docs badge]][docs] [![license badge]][license]

[crates.io badge]: https://img.shields.io/crates/v/rend.svg
[crates.io]: https://crates.io/crates/rend
[License]: https://img.shields.io/badge/license-MIT-blue.svg
[license path]: https://github.com/djkoloski/rend/blob/master/LICENSE
[docs badge]: https://img.shields.io/docsrs/rend
[docs]: https://docs.rs/rend
[license badge]: https://img.shields.io/badge/license-MIT-blue.svg
[license]: https://github.com/rkyv/rend/blob/master/LICENSE

rend provides cross-platform, endian-aware primitives for Rust.

rend is a library that provides endian-aware primitives for Rust.
## Documentation

---
- [rend](https://docs.rs/rend), provides cross-platform, endian-aware primitives
for Rust

## rend in action
## Example

```rust
use core::mem::transmute;
use rend::*;

let little_int = i32_le::from_native(0x12345678);
// Internal representation is little-endian
assert_eq!(
[0x78, 0x56, 0x34, 0x12],
unsafe { ::core::mem::transmute::<_, [u8; 4]>(little_int) }
unsafe { transmute::<_, [u8; 4]>(little_int) }
);

// Can also be made with `.into()`
Expand All @@ -31,12 +39,12 @@ let big_int = i32_be::from_native(0x12345678);
// Internal representation is big-endian
assert_eq!(
[0x12, 0x34, 0x56, 0x78],
unsafe { ::core::mem::transmute::<_, [u8; 4]>(big_int) }
unsafe { transmute::<_, [u8; 4]>(big_int) }
);

// Can also be made with `.into()`
let big_int: i32_be = 0x12345678.into();
// Still formats correctly
assert_eq!("305419896", format!("{}", big_int));
assert_eq!("0x12345678", format!("0x{:x}", big_int));
```
```
65 changes: 30 additions & 35 deletions crates-io.md → example.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
rend is a library that provides endian-aware primitives for Rust.

---

## rend in action

```rust
use rend::*;

let little_int = i32_le::from_native(0x12345678);
// Internal representation is little-endian
assert_eq!(
[0x78, 0x56, 0x34, 0x12],
unsafe { ::core::mem::transmute::<_, [u8; 4]>(little_int) }
);

// Can also be made with `.into()`
let little_int: i32_le = 0x12345678.into();
// Still formats correctly
assert_eq!("305419896", format!("{}", little_int));
assert_eq!("0x12345678", format!("0x{:x}", little_int));

let big_int = i32_be::from_native(0x12345678);
// Internal representation is big-endian
assert_eq!(
[0x12, 0x34, 0x56, 0x78],
unsafe { ::core::mem::transmute::<_, [u8; 4]>(big_int) }
);

// Can also be made with `.into()`
let big_int: i32_be = 0x12345678.into();
// Still formats correctly
assert_eq!("305419896", format!("{}", big_int));
assert_eq!("0x12345678", format!("0x{:x}", big_int));
```
```rust
use core::mem::transmute;
use rend::*;

let little_int = i32_le::from_native(0x12345678);
// Internal representation is little-endian
assert_eq!(
[0x78, 0x56, 0x34, 0x12],
unsafe { transmute::<_, [u8; 4]>(little_int) }
);

// Can also be made with `.into()`
let little_int: i32_le = 0x12345678.into();
// Still formats correctly
assert_eq!("305419896", format!("{}", little_int));
assert_eq!("0x12345678", format!("0x{:x}", little_int));

let big_int = i32_be::from_native(0x12345678);
// Internal representation is big-endian
assert_eq!(
[0x12, 0x34, 0x56, 0x78],
unsafe { transmute::<_, [u8; 4]>(big_int) }
);

// Can also be made with `.into()`
let big_int: i32_be = 0x12345678.into();
// Still formats correctly
assert_eq!("305419896", format!("{}", big_int));
assert_eq!("0x12345678", format!("0x{:x}", big_int));
```
14 changes: 14 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
max_width = 80
comment_width = 80
wrap_comments = true
group_imports = "StdExternalCrate"
imports_granularity = "Crate"
condense_wildcard_suffixes = true
error_on_line_overflow = true
error_on_unformatted = true
format_code_in_doc_comments = true
format_macro_matchers = true
format_macro_bodies = true
format_strings = true
hex_literal_case = "Lower"
normalize_comments = true
use_field_init_shorthand = true
50 changes: 13 additions & 37 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,50 +1,21 @@
//! # rend
//!
//! rend is a library that provides cross-platform primitives for Rust.
//! rend provides cross-platform, endian-aware primitives for Rust.
//!
//! rend does not provide cross-platform alternatives for types that are
//! inherently cross-platform, such as `bool` and `u8`. It also does not provide
//! cross-platform types for types that have an architecture-dependent size,
//! such as `isize` and `usize`. rend does not support custom types.
//! cross-platform alternatives for types that have an architecture-dependent
//! size, such as `isize` and `usize`. rend does not support custom types.
//!
//! rend is intended to be used to build portable types that can be shared
//! between different architectures, especially with zero-copy deserialization.
//! between different architectures.
//!
//! ## Features
//!
//! - `bytecheck`: Enables support for validating types using `bytecheck`
//! - `bytecheck`: Enables support for validating types using `bytecheck`.
//!
//! ## Example:
//! ```
//! use rend::*;
//!
//! let little_int = i32_le::from_native(0x12345678);
//! // Internal representation is little-endian
//! assert_eq!(
//! [0x78, 0x56, 0x34, 0x12],
//! unsafe { ::core::mem::transmute::<_, [u8; 4]>(little_int) }
//! );
//!
//! // Can also be made with `.into()`
//! let little_int: i32_le = 0x12345678.into();
//! // Still formats correctly
//! assert_eq!("305419896", format!("{}", little_int));
//! assert_eq!("0x12345678", format!("0x{:x}", little_int));
//!
//! let big_int = i32_be::from_native(0x12345678);
//! // Internal representation is big-endian
//! assert_eq!(
//! [0x12, 0x34, 0x56, 0x78],
//! unsafe { ::core::mem::transmute::<_, [u8; 4]>(big_int) }
//! );
//!
//! // Can also be made with `.into()`
//! let big_int: i32_be = 0x12345678.into();
//! // Still formats correctly
//! assert_eq!("305419896", format!("{}", big_int));
//! assert_eq!("0x12345678", format!("0x{:x}", big_int));
//! ```

#![doc = include_str!("../example.md")]
#![no_std]
#![deny(
future_incompatible,
Expand All @@ -59,6 +30,7 @@
rustdoc::broken_intra_doc_links,
rustdoc::missing_crate_level_docs
)]
#![cfg_attr(all(docsrs, not(doctest)), feature(doc_cfg, doc_auto_cfg))]

#[macro_use]
mod common;
Expand Down Expand Up @@ -153,7 +125,10 @@ define_unsigned_integers! {
}

macro_rules! define_float {
($name:ident: $endian:ident $size_align:literal $prim:ty as $prim_int:ty) => {
(
$name:ident:
$endian:ident $size_align:literal $prim:ty as $prim_int:ty
) => {
define_newtype!($name: $endian $size_align $prim);
impl_float!($name: $endian $prim as $prim_int);
};
Expand Down Expand Up @@ -668,9 +643,10 @@ define_atomics! {

#[cfg(test)]
mod tests {
use super::*;
use core::mem::transmute;

use super::*;

#[test]
fn signed_integers() {
assert_size_align! {
Expand Down
Loading

0 comments on commit 777d1ce

Please sign in to comment.