Skip to content

Commit

Permalink
Update README, docs, and manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
djkoloski committed Aug 11, 2024
1 parent d37319e commit 0053235
Show file tree
Hide file tree
Showing 12 changed files with 986 additions and 967 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ env:

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

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

toolchain:
name: Toolchain / ${{ matrix.toolchain }} ${{ matrix.opt }}
Expand Down
22 changes: 12 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
members = [
"bytecheck",
"bytecheck_derive",
"bytecheck_test",
]
resolver = "2"

Expand All @@ -11,19 +10,22 @@ version = "0.8.0-alpha.9"
authors = ["David Koloski <djkoloski@gmail.com>"]
edition = "2021"
license = "MIT"
documentation = "https://docs.rs/bytecheck"
readme = "README.md"
repository = "https://github.com/rkyv/bytecheck"
keywords = ["no_std", "validation", "serialization"]
categories = ["encoding", "no-std", "no-std::no-alloc"]

[workspace.dependencies]
bytecheck = { version = "0.8.0-alpha.9", path = "bytecheck", default-features = false }
bytecheck_derive = { version = "0.8.0-alpha.9", path = "bytecheck_derive", default-features = false }
proc-macro2 = { version = "1.0", default-features = false }
ptr_meta = { version = "0.3.0-alpha.2", default-features = false }
rancor = { version = "0.1.0-alpha.9", default-features = false }
bytecheck = { version = "=0.8.0-alpha.9", path = "bytecheck", default-features = false }
bytecheck_derive = { version = "=0.8.0-alpha.9", path = "bytecheck_derive", default-features = false }
proc-macro2 = { version = "1", default-features = false }
ptr_meta = { version = "=0.3.0-alpha.3", default-features = false }
rancor = { version = "=0.1.0-alpha.9", default-features = false }
simdutf8 = { version = "0.1", default-features = false }
syn = { version = "2.0", features = ["full"] }
uuid = { version = "1.4", default-features = false }
quote = { version = "1.0", default-features = false }
syn = { version = "2", default-features = false }
uuid = { version = "1", default-features = false }
quote = { version = "1", default-features = false }

[patch.crates-io]
ptr_meta = { git = "https://github.com/rkyv/ptr_meta" }
rancor = { git = "https://github.com/rkyv/rancor" }
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# bytecheck &emsp; [![Latest Version]][crates.io] [![License]][license path]
# `bytecheck`

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

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

bytecheck is a memory validation framework for Rust.

## Documentation

bytecheck is a type validation framework for Rust.
- [bytecheck](https://docs.rs/bytecheck), a memory validation framework for Rust
- [bytecheck_derive](https://docs.rs/bytecheck_derive), the derive macro for
bytecheck

## bytecheck in action
## Example

```rust
use bytecheck::{CheckBytes, check_bytes, rancor::Failure};
Expand Down
16 changes: 9 additions & 7 deletions bytecheck/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
[package]
name = "bytecheck"
description = "Derive macro for bytecheck"
documentation = "https://docs.rs/bytecheck"
keywords = ["bytecheck", "validation", "zero-copy", "rkyv"]
categories = ["encoding"]
description = "Memory validation framework for Rust"
version.workspace = true
edition.workspace = true
authors.workspace = true
edition.workspace = true
license.workspace = true
readme.workspace = true
repository.workspace = true
keywords.workspace = true
categories.workspace = true
documentation = "https://docs.rs/bytecheck"

[dependencies]
bytecheck_derive = { workspace = true, default-features = false }
bytecheck_derive.workspace = true
ptr_meta.workspace = true
rancor.workspace = true
simdutf8 = { workspace = true, optional = true }
Expand All @@ -27,5 +28,6 @@ simdutf8 = { workspace = true, optional = true }
uuid = { workspace = true, optional = true }

[features]
default = ["simdutf8", "std"]
default = ["derive", "simdutf8", "std"]
derive = []
std = ["ptr_meta/std", "rancor/std", "simdutf8?/std", "uuid?/std"]
77 changes: 77 additions & 0 deletions bytecheck/example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
```rust
use bytecheck::{CheckBytes, check_bytes, rancor::Failure};

#[derive(CheckBytes, Debug)]
#[repr(C)]
struct Test {
a: u32,
b: char,
c: bool,
}

#[repr(C, align(4))]
struct Aligned<const N: usize>([u8; N]);

macro_rules! bytes {
($($byte:literal,)*) => {
(&Aligned([$($byte,)*]).0 as &[u8]).as_ptr()
};
($($byte:literal),*) => {
bytes!($($byte,)*)
};
}

// In this example, the architecture is assumed to be little-endian
#[cfg(target_endian = "little")]
unsafe {
// These are valid bytes for a `Test`
check_bytes::<Test, Failure>(
bytes![
0u8, 0u8, 0u8, 0u8,
0x78u8, 0u8, 0u8, 0u8,
1u8, 255u8, 255u8, 255u8,
].cast()
).unwrap();

// Changing the bytes for the u32 is OK, any bytes are a valid u32
check_bytes::<Test, Failure>(
bytes![
42u8, 16u8, 20u8, 3u8,
0x78u8, 0u8, 0u8, 0u8,
1u8, 255u8, 255u8, 255u8,
].cast()
).unwrap();

// Characters outside the valid ranges are invalid
check_bytes::<Test, Failure>(
bytes![
0u8, 0u8, 0u8, 0u8,
0x00u8, 0xd8u8, 0u8, 0u8,
1u8, 255u8, 255u8, 255u8,
].cast()
).unwrap_err();
check_bytes::<Test, Failure>(
bytes![
0u8, 0u8, 0u8, 0u8,
0x00u8, 0x00u8, 0x11u8, 0u8,
1u8, 255u8, 255u8, 255u8,
].cast()
).unwrap_err();

// 0 is a valid boolean value (false) but 2 is not
check_bytes::<Test, Failure>(
bytes![
0u8, 0u8, 0u8, 0u8,
0x78u8, 0u8, 0u8, 0u8,
0u8, 255u8, 255u8, 255u8,
].cast()
).unwrap();
check_bytes::<Test, Failure>(
bytes![
0u8, 0u8, 0u8, 0u8,
0x78u8, 0u8, 0u8, 0u8,
2u8, 255u8, 255u8, 255u8,
].cast()
).unwrap_err();
}
```
Loading

0 comments on commit 0053235

Please sign in to comment.