Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/module_asbytes_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name : asbytes

on :
push :
branches :
- 'alpha'
- 'beta'
- 'master'


env :
CARGO_TERM_COLOR : always

jobs :

# asbytes

test :
uses : Wandalen/wTools/.github/workflows/standard_rust_push.yml@alpha
with :
manifest_path : 'module/core/asbytes/Cargo.toml'
module_name : 'asbytes'
commit_message : ${{ github.event.head_commit.message }}
commiter_username: ${{ github.event.head_commit.committer.username }}
24 changes: 24 additions & 0 deletions .github/workflows/module_graphs_tools_deprecated_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name : graphs_tools_deprecated

on :
push :
branches :
- 'alpha'
- 'beta'
- 'master'


env :
CARGO_TERM_COLOR : always

jobs :

# graphs_tools_deprecated

test :
uses : Wandalen/wTools/.github/workflows/standard_rust_push.yml@alpha
with :
manifest_path : 'module/move/graphs_tools_deprecated/Cargo.toml'
module_name : 'graphs_tools_deprecated'
commit_message : ${{ github.event.head_commit.message }}
commiter_username: ${{ github.event.head_commit.committer.username }}
24 changes: 24 additions & 0 deletions .github/workflows/module_gspread_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name : gspread

on :
push :
branches :
- 'alpha'
- 'beta'
- 'master'


env :
CARGO_TERM_COLOR : always

jobs :

# gspread

test :
uses : Wandalen/wTools/.github/workflows/standard_rust_push.yml@alpha
with :
manifest_path : 'module/move/gspread/Cargo.toml'
module_name : 'gspread'
commit_message : ${{ github.event.head_commit.message }}
commiter_username: ${{ github.event.head_commit.committer.username }}
24 changes: 24 additions & 0 deletions .github/workflows/module_llm_tools_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name : llm_tools

on :
push :
branches :
- 'alpha'
- 'beta'
- 'master'


env :
CARGO_TERM_COLOR : always

jobs :

# llm_tools

test :
uses : Wandalen/wTools/.github/workflows/standard_rust_push.yml@alpha
with :
manifest_path : 'module/move/llm_tools/Cargo.toml'
module_name : 'llm_tools'
commit_message : ${{ github.event.head_commit.message }}
commiter_username: ${{ github.event.head_commit.committer.username }}
29 changes: 29 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ version = "~0.12.0"
path = "module/core/is_slice"
default-features = false

[workspace.dependencies.asbytes]
version = "~0.1.0"
path = "module/core/asbytes"
default-features = false


## error

Expand Down Expand Up @@ -592,3 +597,27 @@ version = "0.8.5"

[workspace.dependencies.trybuild]
version = "1.0.85"

[workspace.dependencies.futures-core]
version = "0.3.31"

[workspace.dependencies.futures-util]
version = "0.3.31"

[workspace.dependencies.regex]
version = "1.11.1"

[workspace.dependencies.serde]
version = "1.0.219"

[workspace.dependencies.serde_with]
version = "3.12.0"

[workspace.dependencies.serde_json]
version = "1.0.140"

[workspace.dependencies.serde_yaml]
version = "0.9.34"

[workspace.dependencies.bytemuck]
version = "1.21.0"
16 changes: 10 additions & 6 deletions Readme.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion module/alias/proc_macro_tools/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Module :: proc_macro_tools
<!--{ generate.module_header.start() }-->
[![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/module_proc_macro_tools_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_proc_macro_tools_push.yml) [![docs.rs](https://img.shields.io/docsrs/proc_macro_tools?color=e3e8f0&logo=docs.rs)](https://docs.rs/proc_macro_tools) [![Open in Gitpod](https://raster.shields.io/static/v1?label=try&message=online&color=eee&logo=gitpod&logoColor=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Falias%2Fproc_macro_tools%2Fexamples%2Fproc_macro_tools_trivial.rs,RUN_POSTFIX=--example%20proc_macro_tools_trivial/https://github.com/Wandalen/wTools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY)
[![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/module_proc_macro_tools_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_proc_macro_tools_push.yml) [![docs.rs](https://img.shields.io/docsrs/proc_macro_tools?color=e3e8f0&logo=docs.rs)](https://docs.rs/proc_macro_tools) [![Open in Gitpod](https://raster.shields.io/static/v1?label=try&message=online&color=eee&logo=gitpod&logoColor=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Falias%2Fproc_macro_tools%2Fexamples%2Fproc_macro_tools_trivial.rs,RUN_POSTFIX=--example%20module%2Falias%2Fproc_macro_tools%2Fexamples%2Fproc_macro_tools_trivial.rs/https://github.com/Wandalen/wTools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY)
<!--{ generate.module_header.end }-->

Tools for writing procedural macros.
Expand Down
2 changes: 1 addition & 1 deletion module/alias/werror/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Module :: werror
<!--{ generate.module_header.start() }-->
[![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/module_werror_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_werror_push.yml) [![docs.rs](https://img.shields.io/docsrs/werror?color=e3e8f0&logo=docs.rs)](https://docs.rs/werror) [![Open in Gitpod](https://raster.shields.io/static/v1?label=try&message=online&color=eee&logo=gitpod&logoColor=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Falias%2Fwerror%2Fexamples%2Fwerror_tools_trivial.rs,RUN_POSTFIX=--example%20werror_tools_trivial/https://github.com/Wandalen/wTools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY)
[![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/module_werror_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_werror_push.yml) [![docs.rs](https://img.shields.io/docsrs/werror?color=e3e8f0&logo=docs.rs)](https://docs.rs/werror) [![Open in Gitpod](https://raster.shields.io/static/v1?label=try&message=online&color=eee&logo=gitpod&logoColor=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Falias%2Fwerror%2Fexamples%2Fwerror_tools_trivial.rs,RUN_POSTFIX=--example%20module%2Falias%2Fwerror%2Fexamples%2Fwerror_tools_trivial.rs/https://github.com/Wandalen/wTools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY)
<!--{ generate.module_header.end }-->

Basic exceptions handling mechanism.
Expand Down
2 changes: 1 addition & 1 deletion module/alias/winterval/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Module :: winterval
<!--{ generate.module_header.start() }-->
[![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/module_winterval_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_winterval_push.yml) [![docs.rs](https://img.shields.io/docsrs/winterval?color=e3e8f0&logo=docs.rs)](https://docs.rs/winterval) [![Open in Gitpod](https://raster.shields.io/static/v1?label=try&message=online&color=eee&logo=gitpod&logoColor=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Falias%2Fwinterval%2Fexamples%2Fwinterval_trivial.rs,RUN_POSTFIX=--example%20winterval_trivial/https://github.com/Wandalen/wTools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY)
[![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/module_winterval_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_winterval_push.yml) [![docs.rs](https://img.shields.io/docsrs/winterval?color=e3e8f0&logo=docs.rs)](https://docs.rs/winterval) [![Open in Gitpod](https://raster.shields.io/static/v1?label=try&message=online&color=eee&logo=gitpod&logoColor=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Falias%2Fwinterval%2Fexamples%2Fwinterval_trivial.rs,RUN_POSTFIX=--example%20module%2Falias%2Fwinterval%2Fexamples%2Fwinterval_trivial.rs/https://github.com/Wandalen/wTools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY)
<!--{ generate.module_header.end }-->

Integer interval adapter for both Range and RangeInclusive.
Expand Down
2 changes: 1 addition & 1 deletion module/alias/wstring_tools/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Module :: wstring_tools
<!--{ generate.module_header.start() }-->
[![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/module_wstring_tools_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_wstring_tools_push.yml) [![docs.rs](https://img.shields.io/docsrs/wstring_tools?color=e3e8f0&logo=docs.rs)](https://docs.rs/wstring_tools) [![Open in Gitpod](https://raster.shields.io/static/v1?label=try&message=online&color=eee&logo=gitpod&logoColor=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Falias%2Fwstring_tools%2Fexamples%2Fwstring_toolst_trivial_sample.rs,RUN_POSTFIX=--example%20wstring_toolst_trivial_sample/https://github.com/Wandalen/wTools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY)
[![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/module_wstring_tools_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_wstring_tools_push.yml) [![docs.rs](https://img.shields.io/docsrs/wstring_tools?color=e3e8f0&logo=docs.rs)](https://docs.rs/wstring_tools) [![Open in Gitpod](https://raster.shields.io/static/v1?label=try&message=online&color=eee&logo=gitpod&logoColor=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Falias%2Fwstring_tools%2Fexamples%2Fwstring_toolst_trivial_sample.rs,RUN_POSTFIX=--example%20module%2Falias%2Fwstring_tools%2Fexamples%2Fwstring_toolst_trivial_sample.rs/https://github.com/Wandalen/wTools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY)
<!--{ generate.module_header.end }-->

Tools to manipulate strings.
Expand Down
2 changes: 1 addition & 1 deletion module/alias/wtest/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Module :: wtest
<!--{ generate.module_header.start() }-->
[![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/module_wtest_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_wtest_push.yml) [![docs.rs](https://img.shields.io/docsrs/wtest?color=e3e8f0&logo=docs.rs)](https://docs.rs/wtest) [![Open in Gitpod](https://raster.shields.io/static/v1?label=try&message=online&color=eee&logo=gitpod&logoColor=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Falias%2Fwtest%2Fexamples%2Fwtest_trivial_sample.rs,RUN_POSTFIX=--example%20wtest_trivial_sample/https://github.com/Wandalen/wTools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY)
[![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/module_wtest_push.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/module_wtest_push.yml) [![docs.rs](https://img.shields.io/docsrs/wtest?color=e3e8f0&logo=docs.rs)](https://docs.rs/wtest) [![Open in Gitpod](https://raster.shields.io/static/v1?label=try&message=online&color=eee&logo=gitpod&logoColor=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=module%2Falias%2Fwtest%2Fexamples%2Fwtest_trivial_sample.rs,RUN_POSTFIX=--example%20module%2Falias%2Fwtest%2Fexamples%2Fwtest_trivial_sample.rs/https://github.com/Wandalen/wTools) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY)
<!--{ generate.module_header.end }-->

Tools for writing and running tests.
Expand Down
44 changes: 44 additions & 0 deletions module/core/asbytes/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "asbytes"
version = "0.1.0"
edition = "2021"
authors = [
"Kostiantyn Wandalen <[email protected]>",
]
license = "MIT"
readme = "Readme.md"
documentation = "https://docs.rs/asbytes"
repository = "https://github.com/Wandalen/wTools/tree/master/module/core/asbytes"
homepage = "https://github.com/Wandalen/wTools/tree/master/module/core/asbytes"
description = """
Unified and ergonomic abstraction for converting various data structures into raw byte slices.
"""
categories = [ "algorithms", "development-tools" ]
keywords = [ "fundamental", "general-purpose" ]

[lints]
workspace = true

[package.metadata.docs.rs]
features = [ "full" ]
all-features = false

[features]
default = [ "enabled", "as_bytes", "derive", "must_cast" ]
full = [ "default" ]
enabled = []
as_bytes = [ "dep:bytemuck" ]

derive = [ "bytemuck/derive" ] # Provide derive macros for the various traits.
extern_crate_alloc = [ "bytemuck/extern_crate_alloc" ] # Provide utilities for alloc related types such as Box and Vec.
zeroable_maybe_uninit = [ "bytemuck/zeroable_maybe_uninit" ] # and zeroable_atomics: Provide more Zeroable impls.
wasm_simd = [ "bytemuck/wasm_simd" ] # Support more SIMD types.
aarch64_simd = [ "bytemuck/aarch64_simd" ] # Support more SIMD types.
min_const_generics = [ "bytemuck/min_const_generics" ] # Provides appropriate impls for arrays of all lengths instead of just for a select list of array lengths.
must_cast = [ "bytemuck/must_cast" ] # Provides the must_ functions, which will compile error if the requested cast can’t be statically verified.
const_zeroed = [ "bytemuck/const_zeroed" ] #

[dependencies]
bytemuck = { workspace = true, optional = true }

[dev-dependencies]
22 changes: 22 additions & 0 deletions module/core/asbytes/License
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright Kostiantyn Mysnyk and Out of the Box Systems (c) 2021-2024

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
83 changes: 83 additions & 0 deletions module/core/asbytes/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<!-- {{# generate.module_header{} #}} -->

# Module :: asbytes
[![experimental](https://raster.shields.io/static/v1?label=stability&message=experimental&color=orange&logoColor=eee)](https://github.com/emersion/stability-badges#experimental) [![rust-status](https://github.com/Wandalen/wTools/actions/workflows/ModuleasbytesPush.yml/badge.svg)](https://github.com/Wandalen/wTools/actions/workflows/ModuleasbytesPush.yml) [![docs.rs](https://img.shields.io/docsrs/asbytes?color=e3e8f0&logo=docs.rs)](https://docs.rs/asbytes) [![discord](https://img.shields.io/discord/872391416519737405?color=eee&logo=discord&logoColor=eee&label=ask)](https://discord.gg/m3YfbXpUUY)

The `asbytes` crate provides a convenient trait, `AsBytes`, for viewing common data structures as raw byte slices (`&[u8]`). It focuses on types that are safe to represent as bytes (Plain Old Data, or POD), leveraging the safety guarantees of the underlying `bytemuck` crate.

## Why `asbytes`?

While `bytemuck` provides the core functionality for safe byte-level casting (like `bytemuck::cast_slice` for collections and `bytemuck::bytes_of` for single items), `asbytes` offers a unified trait-based approach for common use cases:

1. **Consistency:** The `AsBytes` trait provides a single method, `.as_bytes()`, that works consistently across supported types like `Vec<T>`, slices (`&[T]`), arrays (`[T; N]`), and single POD items wrapped in a tuple `(T,)`.
2. **Readability:** Calling `.as_bytes()` clearly signals the intent to get the raw byte representation, which is useful for tasks like serialization, hashing, or interfacing with low-level APIs (graphics, networking, etc.).
3. **Simpler Generics:** Functions can accept `T: AsBytes` to work generically with the byte representation of different compatible data structures.
4. **Convenience:** The trait also provides `.byte_size()` and `.len()` methods for easily getting the size in bytes and the number of elements, respectively.

Essentially, `asbytes` acts as a focused convenience layer on top of `bytemuck` for the specific task of viewing data as bytes via a consistent trait method.

## How asbytes Differs from bytemuck

While bytemuck offers safe transmutation via its `Pod` trait and functions like `cast_slice`, it does not expose a dedicated trait for converting data structures into byte slices. `asbytes` introduces the `AsBytes` trait, abstracting these conversions and providing additional conveniences—such as direct byte size computation—on top of bytemuck's proven foundation.

### Example

```rust
// Make sure bytemuck is available for derives
extern crate bytemuck;
use asbytes::AsBytes; // Import the trait

// Define a POD struct
#[ repr( C ) ]
#[ derive( Clone, Copy, bytemuck::Pod, bytemuck::Zeroable ) ]
struct Point
{
x : f32,
y : f32,
}

fn main()
{
// --- Collections ---
let points_vec : Vec< Point > = vec![ Point { x : 1.0, y : 2.0 }, Point { x : 3.0, y : 4.0 } ];
let points_slice : &[ Point ] = &points_vec[ .. ];
let points_array : [ Point; 1 ] = [ Point { x : 5.0, y : 6.0 } ];

let vec_bytes = points_vec.as_bytes();
let slice_bytes = points_slice.as_bytes();
let array_bytes = points_array.as_bytes();

println!( "Vec Bytes: length={}, data={:?}", points_vec.byte_size(), vec_bytes );
println!( "Slice Bytes: length={}, data={:?}", slice_bytes.byte_size(), slice_bytes );
println!( "Array Bytes: length={}, data={:?}", points_array.byte_size(), array_bytes );
println!( "Vec Element Count: {}", points_vec.len() ); // Output: 2
println!( "Array Element Count: {}", points_array.len() ); // Output: 1

// --- Single POD Item (using tuple trick) ---
let single_point = Point { x : -1.0, y : -2.0 };
let single_point_tuple = ( single_point, ); // Wrap in a single-element tuple

let point_bytes = single_point_tuple.as_bytes();
println!( "Single Point Bytes: length={}, data={:?}", single_point_tuple.byte_size(), point_bytes );
println!( "Single Point Element Count: {}", single_point_tuple.len() ); // Output: 1

let scalar_tuple = ( 12345u32, );
let scalar_bytes = scalar_tuple.as_bytes();
println!( "Scalar Bytes: length={}, data={:?}", scalar_tuple.byte_size(), scalar_bytes );
}
```

### To add to your project

```sh
cargo add asbytes
```

### Try out from the repository

```sh
git clone https://github.com/Wandalen/wTools
cd wTools
cd examples/asbytes
cargo run
```
Loading