Explorar el Código

update things

deltanedas hace 1 mes
padre
commit
7b318563ab
Se han modificado 7 ficheros con 28 adiciones y 29 borrados
  1. 5 4
      Cargo.toml
  2. 1 1
      LICENSE
  3. 2 0
      README.md
  4. 3 3
      orio-derive/Cargo.toml
  5. 2 2
      orio-derive/src/lib.rs
  6. 12 17
      src/impls.rs
  7. 3 2
      src/lib.rs

+ 5 - 4
Cargo.toml

@@ -1,8 +1,9 @@
 [package]
 name = "orio"
-version = "0.6.0"
+version = "0.7.0"
 authors = ["deltanedas"]
-edition = "2021"
+edition = "2024"
+rust-version = "1.85"
 readme = "README.md"
 description = "Small serialization library"
 repository = "https://gitgud.io/deltanedas/orio"
@@ -14,8 +15,8 @@ keywords = ["serialization"]
 # only used as a workaround to array try_from_fn not being stable
 arrayvec = "0.7"
 byteorder = "1"
-orio-derive = {path = "orio-derive", version = "0.5.1", optional = true}
-paste = "1"
+orio-derive = {path = "orio-derive", version = "0.7.0", optional = true}
+pastey = "0.2"
 utf8-chars = {version = "3", optional = true}
 
 [features]

+ 1 - 1
LICENSE

@@ -1,6 +1,6 @@
 MIT License
 
-Copyright (c) 2023 deltanedas
+Copyright (c) 2026 deltanedas
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal

+ 2 - 0
README.md

@@ -2,6 +2,8 @@
 
 Lightweight and clean alternative to serde, focusing on writing to and from `Vec<u8>`s.
 
+MSRV is 1.85.0
+
 ```rs
 #[derive(Io)]
 struct Thingy {

+ 3 - 3
orio-derive/Cargo.toml

@@ -1,8 +1,8 @@
 [package]
 name = "orio-derive"
-version = "0.5.1"
+version = "0.7.0"
 authors = ["deltanedas"]
-edition = "2021"
+edition = "2024"
 readme = "README.md"
 description = "Derive macro for orio, a small serialization library"
 repository = "https://gitgud.io/deltanedas/orio"
@@ -12,7 +12,7 @@ keywords = ["serialization"]
 
 [dependencies]
 proc-macro2 = "1"
-syn = {version = "2", features = ["full"]}
+syn = {version = "3", features = ["full"]}
 quote = "1"
 
 [lib]

+ 2 - 2
orio-derive/src/lib.rs

@@ -183,7 +183,7 @@ fn read_fields(base: TokenStream2, fields: &Fields) -> TokenStream2 {
 			let read_fields = fields.named.iter()
 				.map(|field| {
 					let ident = &field.ident;
-					let read = read_field(&field);
+					let read = read_field(field);
 					quote! {
 						#ident: #read
 					}
@@ -196,7 +196,7 @@ fn read_fields(base: TokenStream2, fields: &Fields) -> TokenStream2 {
 		},
 		Fields::Unnamed(fields) => {
 			let read_fields = fields.unnamed.iter()
-				.map(|field| read_field(&field));
+				.map(read_field);
 			quote! {
 				#base(#(#read_fields),*)
 			}

+ 12 - 17
src/impls.rs

@@ -3,14 +3,14 @@ use crate::*;
 use std::{
 	collections::HashMap,
 	hash::Hash,
-	io::{Error, ErrorKind, Read, Result, Write},
+	io::{Error, Read, Result, Write},
 	mem::size_of,
 	ops::Deref,
 	time::{Duration, SystemTime, UNIX_EPOCH}
 };
 
 use arrayvec::ArrayVec;
-use paste::paste;
+use pastey::paste;
 
 macro_rules! impl_basic {
 	($type:ty) => {
@@ -108,7 +108,7 @@ impl Io for char {
 	fn read(r: &mut Reader) -> Result<Self> {
 		use utf8_chars::BufReadCharsExt;
 		r.read_char()?
-			.ok_or_else(|| other("unexpected EOF"))
+			.ok_or_else(|| Error::other("unexpected EOF"))
 	}
 
 	fn write(&self, w: &mut Writer) -> Result<()> {
@@ -129,12 +129,12 @@ impl Io for usize {
 	fn read(r: &mut Reader) -> Result<Self> {
 		u64::read(r)?
 			.try_into()
-			.map_err(other)
+			.map_err(Error::other)
 	}
 
 	fn write(&self, w: &mut Writer) -> Result<()> {
 		u64::try_from(*self)
-			.map_err(other)?
+			.map_err(Error::other)?
 			.write(w)
 	}
 
@@ -205,7 +205,7 @@ impl LenIo for String {
 		let mut bytes = vec![0; len as usize];
 		r.read_exact(&mut bytes)?;
 		Self::from_utf8(bytes)
-			.map_err(other)
+			.map_err(Error::other)
 	}
 
 	fn write<L: Len>(&self, w: &mut Writer) -> Result<()> {
@@ -290,7 +290,7 @@ impl LenIo for Duration {
 
 	fn write<L: Len>(&self, w: &mut Writer) -> Result<()> {
 		let ms = u64::try_from(self.as_millis())
-			.map_err(other)?;
+			.map_err(Error::other)?;
 		L::try_from(ms)
 			.map_err(conversion)?
 			.write(w)
@@ -312,9 +312,9 @@ impl Io for SystemTime {
 
 	fn write(&self, w: &mut Writer) -> Result<()> {
 		u64::try_from(self.duration_since(UNIX_EPOCH)
-			.map_err(other)
+			.map_err(Error::other)
 			.map(|offset| offset.as_millis())?)
-			.map_err(other)?
+			.map_err(Error::other)?
 			.write(w)
 	}
 
@@ -356,7 +356,7 @@ impl LenIo for &str {
 	fn write<L: Len>(&self, w: &mut Writer) -> Result<()> {
 		let len = L::try_from(self.len() as u64)
 			.map_err(conversion)
-			.map_err(other)?;
+			.map_err(Error::other)?;
 		len.write(w)?;
 		w.write_all(self.as_bytes())
 	}
@@ -405,16 +405,11 @@ impl<T: Io> Io for &T {
 	}
 }
 
-// basically Error::other but not requiring nightly
-fn other(error: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Error {
-	Error::new(ErrorKind::Other, error)
-}
-
 // discard error and use a string
 fn conversion<T>(_: T) -> Error {
-	other("failed to convert length to u64")
+	Error::other("failed to convert length to u64")
 }
 
 fn immutable_read() -> Error {
-	other("immutable references cannot be read into")
+	Error::other("immutable references cannot be read into")
 }

+ 3 - 2
src/lib.rs

@@ -12,6 +12,7 @@
 //! Fields can have the `#[io(ignore)]` attribute added which will:
 //! 1. Ignore the field when writing the full struct/enum.
 //! 2. Use `Default` for reading as there is nothing to read from.
+//!
 //! Some types like `String` or `Vec` have a length field which can be changed.
 //! To use these, add the `#[io(len(TYPE))]` attribute, where TYPE is an int like u8, u16, etc.
 //! This lets you customize how much data you want a field to support, e.g. for a filename 255 bytes
@@ -37,12 +38,12 @@ pub use orio_derive::*;
 
 pub use crate::io::*;
 
-use std::io::{Error, ErrorKind};
+use std::io::Error;
 
 pub(crate) use byteorder::LittleEndian as LE;
 
 /// Helper for enum [Io::read] implementations to use.
 #[cfg(feature = "derive")]
 pub fn derive_enum_variant_error(variant: usize, ident: &str) -> Error {
-	Error::new(ErrorKind::Other, format!("Invalid enum variant {variant} for {ident}"))
+	Error::other(format!("Invalid enum variant {variant} for {ident}"))
 }