Skip to content

Commit

Permalink
Fix some generic type casing
Browse files Browse the repository at this point in the history
  • Loading branch information
vE5li committed Apr 23, 2024
1 parent cd72734 commit c99dea1
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 70 deletions.
2 changes: 1 addition & 1 deletion korangar/src/graphics/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Transform {
}

impl FromBytes for Transform {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
let mut position = <Vector3<f32>>::from_bytes(byte_stream).trace::<Self>()?;
let rotation = <Vector3<f32>>::from_bytes(byte_stream).trace::<Self>()?;
let scale = <Vector3<f32>>::from_bytes(byte_stream).trace::<Self>()?;
Expand Down
14 changes: 7 additions & 7 deletions korangar/src/interface/elements/miscellanious/chat/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use crate::network::ChatMessage;
/// prevent calling the same method multiple times and calling
/// [`build`](Self::build) before the mandatory methods have been called.
#[must_use = "`build` needs to be called"]
pub struct ChatBuilder<MESSAGES, FONT> {
messages: MESSAGES,
font_loader: FONT,
pub struct ChatBuilder<Messages, Font> {
messages: Messages,
font_loader: Font,
}

impl ChatBuilder<Unset, Unset> {
Expand All @@ -26,14 +26,14 @@ impl ChatBuilder<Unset, Unset> {
}
}

impl<FONT> ChatBuilder<Unset, FONT> {
pub fn with_messages(self, messages: PlainRemote<Vec<ChatMessage>>) -> ChatBuilder<PlainRemote<Vec<ChatMessage>>, FONT> {
impl<Font> ChatBuilder<Unset, Font> {
pub fn with_messages(self, messages: PlainRemote<Vec<ChatMessage>>) -> ChatBuilder<PlainRemote<Vec<ChatMessage>>, Font> {
ChatBuilder { messages, ..self }
}
}

impl<MESSAGES> ChatBuilder<MESSAGES, Unset> {
pub fn with_font_loader(self, font_loader: Rc<RefCell<FontLoader>>) -> ChatBuilder<MESSAGES, Rc<RefCell<FontLoader>>> {
impl<Messages> ChatBuilder<Messages, Unset> {
pub fn with_font_loader(self, font_loader: Rc<RefCell<FontLoader>>) -> ChatBuilder<Messages, Rc<RefCell<FontLoader>>> {
ChatBuilder { font_loader, ..self }
}
}
Expand Down
2 changes: 1 addition & 1 deletion korangar/src/loaders/map/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl GroundTile {
}

impl FromBytes for GroundTile {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
let upper_left_height = f32::from_bytes(byte_stream).trace::<Self>()?;
let upper_right_height = f32::from_bytes(byte_stream).trace::<Self>()?;
let lower_left_height = f32::from_bytes(byte_stream).trace::<Self>()?;
Expand Down
2 changes: 1 addition & 1 deletion korangar/src/loaders/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::world::*;
const MAP_OFFSET: f32 = 5.0;

#[cfg(feature = "debug")]
fn assert_byte_stream_empty<META>(mut byte_stream: ByteStream<META>, file_name: &str) {
fn assert_byte_stream_empty<Meta>(mut byte_stream: ByteStream<Meta>, file_name: &str) {
use korangar_debug::logging::{print_debug, Colorize};

if byte_stream.is_empty() {
Expand Down
4 changes: 2 additions & 2 deletions korangar/src/loaders/map/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum ResourceType {
}

impl FromBytes for ResourceType {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
let index = i32::from_bytes(byte_stream).trace::<Self>()?;
match index {
1 => Ok(ResourceType::Object),
Expand Down Expand Up @@ -65,7 +65,7 @@ pub struct MapResources {
}

impl FromBytes for MapResources {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
let resources_amount = i32::from_bytes(byte_stream).trace::<Self>()? as usize;

let mut objects = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion korangar/src/loaders/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub struct ModelString<const LENGTH: usize> {
}

impl<const LENGTH: usize> FromBytes for ModelString<LENGTH> {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
let inner = if byte_stream
.get_metadata::<Self, Option<InternalVersion>>()?
.ok_or(ConversionError::from_message("version not set"))?
Expand Down
2 changes: 1 addition & 1 deletion korangar/src/loaders/sprite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct PaletteImageData {
struct EncodedData(pub Vec<u8>);

impl FromBytes for PaletteImageData {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self>
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self>
where
Self: Sized,
{
Expand Down
4 changes: 2 additions & 2 deletions korangar/src/loaders/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct Version<T> {
}

impl FromBytes for Version<MajorFirst> {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
let major = byte_stream.byte::<Self>()?;
let minor = byte_stream.byte::<Self>()?;

Expand All @@ -28,7 +28,7 @@ impl FromBytes for Version<MajorFirst> {
}

impl FromBytes for Version<MinorFirst> {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
let minor = byte_stream.byte::<Self>()?;
let major = byte_stream.byte::<Self>()?;

Expand Down
2 changes: 1 addition & 1 deletion korangar/src/world/map/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const CLIFF: u8 = 0b00001000;
pub struct TileType(pub u8);

impl FromBytes for TileType {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
byte_stream.byte::<Self>().map(Self::new)
}
}
Expand Down
6 changes: 3 additions & 3 deletions ragnarok_bytes/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ pub type ConversionResult<T> = Result<T, Box<ConversionError>>;
/// Trait providing stack track helpers to [`ConversionResult`]
pub trait ConversionResultExt {
/// Add a type name to the stack trace.
fn trace<CALLER>(self) -> Self;
fn trace<Caller>(self) -> Self;
}

impl<T> ConversionResultExt for ConversionResult<T> {
fn trace<CALLER>(self) -> Self {
fn trace<Caller>(self) -> Self {
self.map_err(|mut error| {
error.add_to_stack(std::any::type_name::<CALLER>());
error.add_to_stack(std::any::type_name::<Caller>());
error
})
}
Expand Down
34 changes: 17 additions & 17 deletions ragnarok_bytes/src/from_bytes/implement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ use cgmath::{Matrix3, Quaternion, Vector2, Vector3, Vector4};
use crate::{ByteStream, ConversionResult, ConversionResultExt, FromBytes};

impl FromBytes for u8 {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
byte_stream.byte::<Self>()
}
}

impl FromBytes for u16 {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
Ok(Self::from_le_bytes([byte_stream.byte::<Self>()?, byte_stream.byte::<Self>()?]))
}
}

impl FromBytes for u32 {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
Ok(Self::from_le_bytes([
byte_stream.byte::<Self>()?,
byte_stream.byte::<Self>()?,
Expand All @@ -27,7 +27,7 @@ impl FromBytes for u32 {
}

impl FromBytes for u64 {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
Ok(Self::from_le_bytes([
byte_stream.byte::<Self>()?,
byte_stream.byte::<Self>()?,
Expand All @@ -42,19 +42,19 @@ impl FromBytes for u64 {
}

impl FromBytes for i8 {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
Ok(byte_stream.byte::<Self>()? as i8)
}
}

impl FromBytes for i16 {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
Ok(Self::from_le_bytes([byte_stream.byte::<Self>()?, byte_stream.byte::<Self>()?]))
}
}

impl FromBytes for i32 {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
Ok(Self::from_le_bytes([
byte_stream.byte::<Self>()?,
byte_stream.byte::<Self>()?,
Expand All @@ -65,7 +65,7 @@ impl FromBytes for i32 {
}

impl FromBytes for i64 {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
Ok(Self::from_le_bytes([
byte_stream.byte::<Self>()?,
byte_stream.byte::<Self>()?,
Expand All @@ -80,7 +80,7 @@ impl FromBytes for i64 {
}

impl FromBytes for f32 {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
Ok(Self::from_le_bytes([
byte_stream.byte::<Self>()?,
byte_stream.byte::<Self>()?,
Expand All @@ -91,7 +91,7 @@ impl FromBytes for f32 {
}

impl<T: FromBytes, const SIZE: usize> FromBytes for [T; SIZE] {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
use std::mem::MaybeUninit;

let mut data: [MaybeUninit<T>; SIZE] = unsafe { MaybeUninit::uninit().assume_init() };
Expand All @@ -115,7 +115,7 @@ impl<T: FromBytes, const SIZE: usize> FromBytes for [T; SIZE] {
}

impl FromBytes for String {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
let mut value = String::new();

loop {
Expand All @@ -130,7 +130,7 @@ impl FromBytes for String {
}

impl<T: FromBytes> FromBytes for Vec<T> {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
let mut vector = Vec::new();

while !byte_stream.is_empty() {
Expand All @@ -144,7 +144,7 @@ impl<T: FromBytes> FromBytes for Vec<T> {

#[cfg(feature = "cgmath")]
impl<T: FromBytes> FromBytes for Vector2<T> {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
let first = T::from_bytes(byte_stream).trace::<Self>()?;
let second = T::from_bytes(byte_stream).trace::<Self>()?;

Expand All @@ -154,7 +154,7 @@ impl<T: FromBytes> FromBytes for Vector2<T> {

#[cfg(feature = "cgmath")]
impl<T: FromBytes> FromBytes for Vector3<T> {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
let first = T::from_bytes(byte_stream).trace::<Self>()?;
let second = T::from_bytes(byte_stream).trace::<Self>()?;
let third = T::from_bytes(byte_stream).trace::<Self>()?;
Expand All @@ -165,7 +165,7 @@ impl<T: FromBytes> FromBytes for Vector3<T> {

#[cfg(feature = "cgmath")]
impl<T: FromBytes> FromBytes for Vector4<T> {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
let first = T::from_bytes(byte_stream).trace::<Self>()?;
let second = T::from_bytes(byte_stream).trace::<Self>()?;
let third = T::from_bytes(byte_stream).trace::<Self>()?;
Expand All @@ -177,7 +177,7 @@ impl<T: FromBytes> FromBytes for Vector4<T> {

#[cfg(feature = "cgmath")]
impl<T: FromBytes> FromBytes for Quaternion<T> {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
let first = T::from_bytes(byte_stream).trace::<Self>()?;
let second = T::from_bytes(byte_stream).trace::<Self>()?;
let third = T::from_bytes(byte_stream).trace::<Self>()?;
Expand All @@ -189,7 +189,7 @@ impl<T: FromBytes> FromBytes for Quaternion<T> {

#[cfg(feature = "cgmath")]
impl<T: FromBytes> FromBytes for Matrix3<T> {
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self> {
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self> {
let c0r0 = T::from_bytes(byte_stream).trace::<Self>()?;
let c0r1 = T::from_bytes(byte_stream).trace::<Self>()?;
let c0r2 = T::from_bytes(byte_stream).trace::<Self>()?;
Expand Down
8 changes: 4 additions & 4 deletions ragnarok_bytes/src/from_bytes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod implement;
/// Trait to deserialize from a [`ByteStream`].
pub trait FromBytes {
/// Takes bytes from a [`ByteStream`] and deserializes them into a type `T`.
fn from_bytes<META>(byte_stream: &mut ByteStream<META>) -> ConversionResult<Self>
fn from_bytes<Meta>(byte_stream: &mut ByteStream<Meta>) -> ConversionResult<Self>
where
Self: Sized;
}
Expand All @@ -14,7 +14,7 @@ pub trait FromBytes {
pub trait FromBytesExt: FromBytes {
/// Takes a fixed number of bytes from the [`ByteStream`] and tries to
/// deserialize them into a type `T`.
fn from_n_bytes<META>(byte_stream: &mut ByteStream<META>, size: usize) -> ConversionResult<Self>
fn from_n_bytes<Meta>(byte_stream: &mut ByteStream<Meta>, size: usize) -> ConversionResult<Self>
where
Self: Sized;
}
Expand All @@ -24,7 +24,7 @@ where
T: FromBytes,
{
#[allow(clippy::uninit_assumed_init)]
fn from_n_bytes<META>(byte_stream: &mut ByteStream<META>, size: usize) -> ConversionResult<Self>
fn from_n_bytes<Meta>(byte_stream: &mut ByteStream<Meta>, size: usize) -> ConversionResult<Self>
where
Self: Sized,
{
Expand All @@ -48,7 +48,7 @@ mod from_n_bytes {
const TEST_BYTE_SIZE: usize = 4;

impl FromBytes for Test {
fn from_bytes<META>(byte_stream: &mut crate::ByteStream<META>) -> crate::ConversionResult<Self>
fn from_bytes<Meta>(byte_stream: &mut crate::ByteStream<Meta>) -> crate::ConversionResult<Self>
where
Self: Sized,
{
Expand Down
Loading

0 comments on commit c99dea1

Please sign in to comment.