Skip to content

Commit 90db2bb

Browse files
committed
rfc: Change name because binary-utils is taken...
1 parent 330e1d8 commit 90db2bb

File tree

17 files changed

+93
-92
lines changed

17 files changed

+93
-92
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
[package]
2-
name = "binary-utils"
2+
name = "binary-util"
33
version = "0.3.0"
44
authors = ["NetrexMC"]
55
edition = "2021"
66
include = ["src/**/*", "README.md"]
77
description = "A panic-free way to read/write binary streams in rust."
88
license = "Apache-2.0"
9+
repository = "https://github.com/NetrexMC/binary-util"
910

1011
[dependencies]
1112
codegen = { path = "./codegen", version = "0.1.0", optional = true }

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# binary_utils
1+
# binary_util
22
A panic-free way to read/write binary streams in rust.
33

4-
[Documentation](https://docs.rs/binary_utils/) |
4+
[Documentation](https://docs.rs/binary_util/) |
55
[Discord](https://discord.gg/y4aWA5MQxK)
66

77
## Generic Usage
88
```rust
9-
use binary_utils::{BinaryIo, BinaryReader, BinaryWriter};
9+
use binary_util::{BinaryIo, BinaryReader, BinaryWriter};
1010

1111
#[derive(BinaryIo)]
1212
pub struct MyStruct {
@@ -30,4 +30,4 @@ fn main() {
3030
}
3131
```
3232

33-
For more examples and usage, please refer to the [Documentation](https://docs.rs/binary_utils/).
33+
For more examples and usage, please refer to the [Documentation](https://docs.rs/binary_util/).

codegen/src/io/enums.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ pub(crate) fn derive_enum(
241241
let read_streams = variants.iter().map(|variant| variant.read_content.clone()).collect::<Vec<TokenStream2>>();
242242

243243
quote! {
244-
impl ::binary_utils::interfaces::Writer for #enum_name {
245-
fn write(&self, _binary_writew: &mut ::binary_utils::io::ByteWriter) -> ::std::result::Result<(), ::std::io::Error> {
244+
impl ::binary_util::interfaces::Writer for #enum_name {
245+
fn write(&self, _binary_writew: &mut ::binary_util::io::ByteWriter) -> ::std::result::Result<(), ::std::io::Error> {
246246
match self {
247247
#(#write_streams)*
248248
};
@@ -251,8 +251,8 @@ pub(crate) fn derive_enum(
251251
}
252252
}
253253

254-
impl ::binary_utils::interfaces::Reader<#enum_name> for #enum_name {
255-
fn read(_binary_readerr: &mut ::binary_utils::io::ByteReader) -> ::std::result::Result<#enum_name, ::std::io::Error> {
254+
impl ::binary_util::interfaces::Reader<#enum_name> for #enum_name {
255+
fn read(_binary_readerr: &mut ::binary_util::io::ByteReader) -> ::std::result::Result<#enum_name, ::std::io::Error> {
256256
match <#repr_type>::read(_binary_readerr)? {
257257
#(#read_streams)*
258258
_ => Err(::std::io::Error::new(::std::io::ErrorKind::InvalidData, "Invalid enum discriminant."))

codegen/src/io/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(crate) type AstContext<'a> = (
1313
&'a syn::Visibility,
1414
);
1515

16-
// BinaryEncoder is a derive macro that implements `::binary_utils::interfaces::Reader<T>` and `::binary_utils::interfaces::Writer<T>`
16+
// BinaryEncoder is a derive macro that implements `::binary_util::interfaces::Reader<T>` and `::binary_util::interfaces::Writer<T>`
1717
pub(crate) fn binary_encoder(input: TokenStream) -> TokenStream {
1818
let input = parse_macro_input!(input as DeriveInput);
1919
let ctx: AstContext = (&input.ident, &input.attrs, &input.generics, &input.vis);

codegen/src/io/structs.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub(crate) fn derive_struct(
7878
error_stream.append_all(
7979
syn::Error::new_spanned(
8080
field,
81-
"Cannot have more than one binary_utils Attribute on a single field!",
81+
"Cannot have more than one binary_util Attribute on a single field!",
8282
)
8383
.to_compile_error(),
8484
);
@@ -117,14 +117,14 @@ pub(crate) fn derive_struct(
117117
}
118118
}
119119
quote! {
120-
impl ::binary_utils::interfaces::Writer for #struct_name {
121-
fn write(&self, _binary_writew: &mut ::binary_utils::io::ByteWriter) -> Result<(), ::std::io::Error> {
120+
impl ::binary_util::interfaces::Writer for #struct_name {
121+
fn write(&self, _binary_writew: &mut ::binary_util::io::ByteWriter) -> Result<(), ::std::io::Error> {
122122
#writer
123123
Ok(())
124124
}
125125
}
126-
impl ::binary_utils::interfaces::Reader<#struct_name> for #struct_name {
127-
fn read(_binary_readerr: &mut ::binary_utils::io::ByteReader) -> Result<#struct_name, ::std::io::Error> {
126+
impl ::binary_util::interfaces::Reader<#struct_name> for #struct_name {
127+
fn read(_binary_readerr: &mut ::binary_util::io::ByteReader) -> Result<#struct_name, ::std::io::Error> {
128128
// println!("impl Reader for {} called!\n-> {}", stringify!(#struct_name), stringify!(#reader));
129129
#reader
130130
Ok(Self {
@@ -153,7 +153,7 @@ pub(crate) fn derive_struct(
153153
error_stream.append_all(
154154
syn::Error::new_spanned(
155155
field,
156-
"Cannot have more than one binary_utils Attribute on a field!",
156+
"Cannot have more than one binary_util Attribute on a field!",
157157
)
158158
.to_compile_error(),
159159
);
@@ -198,14 +198,14 @@ pub(crate) fn derive_struct(
198198
// .map(|i| syn::Ident::new(&format!("__unnamed_{}", i), proc_macro2::Span::call_site()))
199199
// .collect();
200200
quote! {
201-
impl ::binary_utils::interfaces::Writer for #struct_name {
202-
fn write(&self, _binary_writew: &mut ::binary_utils::io::ByteWriter) -> ::std::result::Result<(), ::std::io::Error> {
201+
impl ::binary_util::interfaces::Writer for #struct_name {
202+
fn write(&self, _binary_writew: &mut ::binary_util::io::ByteWriter) -> ::std::result::Result<(), ::std::io::Error> {
203203
#writer
204204
Ok(())
205205
}
206206
}
207-
impl ::binary_utils::interfaces::Reader<#struct_name> for #struct_name {
208-
fn read(_binary_readerr: &mut ::binary_utils::io::ByteReader) -> ::std::result::Result<#struct_name, ::std::io::Error> {
207+
impl ::binary_util::interfaces::Reader<#struct_name> for #struct_name {
208+
fn read(_binary_readerr: &mut ::binary_util::io::ByteReader) -> ::std::result::Result<#struct_name, ::std::io::Error> {
209209
// println!("impl Reader for {} called!\n-> {}", stringify!(#struct_name), stringify!(#reader));
210210
#reader
211211
Ok(Self(
@@ -218,7 +218,7 @@ pub(crate) fn derive_struct(
218218
Fields::Unit => {
219219
error_stream.append_all(syn::Error::new_spanned(
220220
ast_ctx.0,
221-
"Unit structs are not supported by binary_utils because they have no fields to parse or write.\nThis may change in the future, but for now, please use the skip attribute."
221+
"Unit structs are not supported by binary_util because they have no fields to parse or write.\nThis may change in the future, but for now, please use the skip attribute."
222222
).to_compile_error());
223223
return quote!().into();
224224
}

codegen/src/io/unions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ use super::AstContext;
77
pub(crate) fn derive_union(ast_ctx: AstContext, _: DataUnion, _: &mut TokenStream2) -> TokenStream {
88
syn::Error::new_spanned(
99
ast_ctx.0,
10-
"Unions are not supported by binary_utils, there is currently no way to implement the BinaryReader and BinaryWriter traits for unions."
10+
"Unions are not supported by binary_util, there is currently no way to implement the BinaryReader and BinaryWriter traits for unions."
1111
).to_compile_error().into()
1212
}

codegen/src/legacy.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,35 @@ pub fn stream_parse(input: DeriveInput) -> Result<TokenStream> {
1717
Ok(quote! {
1818
#[automatically_derived]
1919
impl Streamable<#name> for #name {
20-
fn parse(&self) -> Result<Vec<u8>, ::binary_utils::error::BinaryError> {
21-
use ::binary_utils::interfaces::{Reader, Writer};
22-
use ::binary_utils::io::ByteWriter;
20+
fn parse(&self) -> Result<Vec<u8>, ::binary_util::error::BinaryError> {
21+
use ::binary_util::interfaces::{Reader, Writer};
22+
use ::binary_util::io::ByteWriter;
2323
let mut writer = ByteWriter::new();
2424
#writes
2525
Ok(writer.as_slice().to_vec())
2626
}
2727

28-
fn compose(s: &[u8], position: &mut usize) -> Result<Self, ::binary_utils::error::BinaryError> {
29-
use ::binary_utils::interfaces::{Reader, Writer};
28+
fn compose(s: &[u8], position: &mut usize) -> Result<Self, ::binary_util::error::BinaryError> {
29+
use ::binary_util::interfaces::{Reader, Writer};
3030
use ::std::io::Read;
31-
let mut source = ::binary_utils::io::ByteReader::from(s);
31+
let mut source = ::binary_util::io::ByteReader::from(s);
3232
Ok(Self {
3333
#reads
3434
})
3535
}
3636
}
3737

38-
impl ::binary_utils::interfaces::Writer for #name {
39-
fn write(&self, writer: &mut ::binary_utils::io::ByteWriter) -> Result<(), ::std::io::Error> {
40-
use ::binary_utils::interfaces::{Reader, Writer};
38+
impl ::binary_util::interfaces::Writer for #name {
39+
fn write(&self, writer: &mut ::binary_util::io::ByteWriter) -> Result<(), ::std::io::Error> {
40+
use ::binary_util::interfaces::{Reader, Writer};
4141
#writes
4242
Ok(())
4343
}
4444
}
4545

46-
impl ::binary_utils::interfaces::Reader<#name> for #name {
47-
fn read(source: &mut ::binary_utils::io::ByteReader) -> Result<Self, ::std::io::Error> {
48-
use ::binary_utils::interfaces::{Reader, Writer};
46+
impl ::binary_util::interfaces::Reader<#name> for #name {
47+
fn read(source: &mut ::binary_util::io::ByteReader) -> Result<Self, ::std::io::Error> {
48+
use ::binary_util::interfaces::{Reader, Writer};
4949
// get the repr type and read it
5050
Ok(Self {
5151
#new_reads
@@ -202,18 +202,18 @@ pub fn stream_parse(input: DeriveInput) -> Result<TokenStream> {
202202

203203
Ok(quote! {
204204
#[automatically_derived]
205-
impl ::binary_utils::interfaces::Streamable<#name> for #name {
206-
fn parse(&self) -> Result<Vec<u8>, ::binary_utils::error::BinaryError> {
207-
use ::binary_utils::interfaces::{Reader, Writer};
205+
impl ::binary_util::interfaces::Streamable<#name> for #name {
206+
fn parse(&self) -> Result<Vec<u8>, ::binary_util::error::BinaryError> {
207+
use ::binary_util::interfaces::{Reader, Writer};
208208
match self {
209209
#(#writers)*
210210
}
211211
}
212212

213-
fn compose(source: &[u8], offset: &mut usize) -> Result<Self, ::binary_utils::error::BinaryError> {
214-
use ::binary_utils::interfaces::{Reader, Writer};
213+
fn compose(source: &[u8], offset: &mut usize) -> Result<Self, ::binary_util::error::BinaryError> {
214+
use ::binary_util::interfaces::{Reader, Writer};
215215
// get the repr type and read it
216-
let v = <#enum_ty>::read(&mut ::binary_utils::io::ByteReader::from(source))?;
216+
let v = <#enum_ty>::read(&mut ::binary_util::io::ByteReader::from(source))?;
217217

218218
match v {
219219
#(#readers)*
@@ -222,18 +222,18 @@ pub fn stream_parse(input: DeriveInput) -> Result<TokenStream> {
222222
}
223223
}
224224

225-
impl ::binary_utils::interfaces::Writer for #name {
226-
fn write(&self, source: &mut ::binary_utils::io::ByteWriter) -> Result<(), ::std::io::Error> {
227-
use ::binary_utils::interfaces::{Reader, Writer};
225+
impl ::binary_util::interfaces::Writer for #name {
226+
fn write(&self, source: &mut ::binary_util::io::ByteWriter) -> Result<(), ::std::io::Error> {
227+
use ::binary_util::interfaces::{Reader, Writer};
228228
match self {
229229
#(#new_writers)*
230230
}
231231
}
232232
}
233233

234-
impl ::binary_utils::interfaces::Reader<#name> for #name {
235-
fn read(source: &mut ::binary_utils::io::ByteReader) -> Result<Self, ::std::io::Error> {
236-
use ::binary_utils::interfaces::{Reader, Writer};
234+
impl ::binary_util::interfaces::Reader<#name> for #name {
235+
fn read(source: &mut ::binary_util::io::ByteReader) -> Result<Self, ::std::io::Error> {
236+
use ::binary_util::interfaces::{Reader, Writer};
237237
// get the repr type and read it
238238
let v = <#enum_ty>::read(source)?;
239239

codegen/src/lib.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ mod legacy;
77
/// **DEPRECATED**.
88
/// This is a legacy proc-macro that is used to generate a BufferStream.
99
/// It provides an easy way to implement the `Streamable` trait.
10-
/// > ⚠️ This proc-macro has been deprecated since `0.3.0` in favor of `binary_utils::interfaces::Reader` and `binary_utils::interfaces::Writer` and will be removed in `0.4.0`.
10+
/// > ⚠️ This proc-macro has been deprecated since `0.3.0` in favor of `binary_util::interfaces::Reader` and `binary_util::interfaces::Writer` and will be removed in `0.4.0`.
1111
///
1212
/// This proc-macro automatically implements the `Streamable` trait for the struct or enum it is applied to.
1313
///
1414
/// Example:
1515
/// ```ignore
16-
/// use binary_utils::BinaryStream;
16+
/// use binary_util::BinaryStream;
1717
///
1818
/// #[derive(BinaryStream)]
1919
/// struct Test {
@@ -29,7 +29,7 @@ mod legacy;
2929
///
3030
/// Please note that this proc-macro does not support unit structs or named enum variants, meaning a code sample like the following will not work:
3131
/// ```warn
32-
/// use binary_utils::BinaryStream;
32+
/// use binary_util::BinaryStream;
3333
///
3434
/// // Error: Unit structs are not supported.
3535
/// #[derive(BinaryStream)]
@@ -53,7 +53,7 @@ pub fn derive_stream(input: TokenStream) -> TokenStream {
5353
.into()
5454
}
5555

56-
/// This proc-macro implements both the `Reader` and `Writer` traits from `binary_utils::interfaces`.
56+
/// This proc-macro implements both the `Reader` and `Writer` traits from `binary_util::interfaces`.
5757
/// It is important to note that not all attributes can be used on all types, and some attributes are exclusive to certain variants.
5858
///
5959
/// ## Structs
@@ -65,8 +65,8 @@ pub fn derive_stream(input: TokenStream) -> TokenStream {
6565
/// The following example will provide both a `Reader` and `Writer` implementation for the struct `ABC`, where each field is encoded as it's respective
6666
/// type to the `Bytewriter`/`Bytereader`.
6767
/// ```ignore
68-
/// use binary_utils::interfaces::{Reader, Writer};
69-
/// use binary_utils::BinaryIo;
68+
/// use binary_util::interfaces::{Reader, Writer};
69+
/// use binary_util::BinaryIo;
7070
///
7171
/// #[derive(BinaryIo, Debug)]
7272
/// struct ABC {
@@ -79,8 +79,8 @@ pub fn derive_stream(input: TokenStream) -> TokenStream {
7979
/// Sometimes it can be more optimal to use Unnamed fields, if you do not care about the field names, and only want to encode/decode the fields in the order they are defined.
8080
/// The behavior of this macro is the same as the previous example, except the fields are unnamed.
8181
/// ```ignore
82-
/// use binary_utils::interfaces::{Reader, Writer};
83-
/// use binary_utils::BinaryIo;
82+
/// use binary_util::interfaces::{Reader, Writer};
83+
/// use binary_util::BinaryIo;
8484
///
8585
/// #[derive(BinaryIo, Debug)]
8686
/// struct ABC(u8, Option<u8>, u8);
@@ -99,8 +99,8 @@ pub fn derive_stream(input: TokenStream) -> TokenStream {
9999
/// The following example will encode the `ProtcolEnum` enum as a `u8`, where each variant is encoded, by default, starting from 0.
100100
///
101101
/// ```ignore
102-
/// use binary_utils::BinaryIo;
103-
/// use binary_utils::{Reader, Writer};
102+
/// use binary_util::BinaryIo;
103+
/// use binary_util::{Reader, Writer};
104104
///
105105
/// #[derive(BinaryIo, Debug)]
106106
/// #[repr(u8)]
@@ -120,8 +120,8 @@ pub fn derive_stream(input: TokenStream) -> TokenStream {
120120
/// The following example makes use of Unnamed variants, in this case `A` to encode both `B` and `C` retrospectively.
121121
/// Where `A::JustC` will be encoded as `0x02` with the binary data of struct `B`.
122122
/// ```ignore
123-
/// use binary_utils::BinaryIo;
124-
/// use binary_utils::{Reader, Writer};
123+
/// use binary_util::BinaryIo;
124+
/// use binary_util::{Reader, Writer};
125125
///
126126
/// #[derive(BinaryIo, Debug)]
127127
/// pub struct B {
@@ -172,8 +172,8 @@ pub fn derive_stream(input: TokenStream) -> TokenStream {
172172
///
173173
/// **Example:**
174174
/// ```ignore
175-
/// use binary_utils::interfaces::{Reader, Writer};
176-
/// use binary_utils::BinaryIo;
175+
/// use binary_util::interfaces::{Reader, Writer};
176+
/// use binary_util::BinaryIo;
177177
///
178178
/// #[derive(BinaryIo, Debug)]
179179
/// struct ABC {
@@ -201,8 +201,8 @@ pub fn derive_stream(input: TokenStream) -> TokenStream {
201201
/// **Example:**
202202
/// In the following example, `b` is explicitly required to be present when encoding, or decoding `ABC`, and it's value is not allowed to be `None`.
203203
/// ```ignore
204-
/// use binary_utils::interfaces::{Reader, Writer};
205-
/// use binary_utils::BinaryIo;
204+
/// use binary_util::interfaces::{Reader, Writer};
205+
/// use binary_util::BinaryIo;
206206
///
207207
/// #[derive(BinaryIo, Debug)]
208208
/// struct ABC {

src/interfaces.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ macro_rules! impl_streamable {
3939
/// Allows you to read from a `ByteReader` without needing to know the type.
4040
///
4141
/// ```ignore
42-
/// use binary_utils::io::{ByteReader, Reader};
42+
/// use binary_util::io::{ByteReader, Reader};
4343
///
4444
/// pub struct MyStruct {
4545
/// pub a: u8,
@@ -186,7 +186,7 @@ impl Reader<SocketAddr> for SocketAddr {
186186
/// Allows you to write to a `ByteWriter` without needing to know the type.
187187
///
188188
/// ```ignore
189-
/// use binary_utils::io::{ByteWriter, Writer};
189+
/// use binary_util::io::{ByteWriter, Writer};
190190
///
191191
/// pub struct MyStruct {
192192
/// pub a: u8,
@@ -324,8 +324,8 @@ impl Writer for SocketAddr {
324324
///
325325
/// ### New Implementation Example
326326
/// ```ignore
327-
/// use binary_utils::io::{ByteReader, ByteWriter};
328-
/// use binary_utils::interfaces::{Reader, Writer};
327+
/// use binary_util::io::{ByteReader, ByteWriter};
328+
/// use binary_util::interfaces::{Reader, Writer};
329329
///
330330
/// pub struct MyStruct;
331331
///
@@ -337,7 +337,7 @@ impl Writer for SocketAddr {
337337
/// A trait to parse and unparse header structs from a given buffer.
338338
///
339339
/// ```ignore
340-
/// use binary_utils::{Streamable, error::BinaryError};
340+
/// use binary_util::{Streamable, error::BinaryError};
341341
///
342342
/// struct Foo {
343343
/// bar: u8,

0 commit comments

Comments
 (0)