use crate::field::{BitArray, DbStr, List, Packed, PackedPrim, UnindexedList};
use alloc::vec::Vec;
pub trait IntoOwned {
type Owned: 'static;
fn into_owned(self) -> Self::Owned;
}
#[macro_export]
macro_rules! impl_identity_owned {
($($ty:ty),* $(,)?) => {
$(
impl $crate::owned::IntoOwned for $ty {
type Owned = Self;
#[inline]
fn into_owned(self) -> Self {
self
}
}
)*
};
}
impl_identity_owned!(i8, u8, i16, u32, i32, f64, bool);
impl IntoOwned for DbStr<'_> {
type Owned = DbStr<'static>;
#[inline]
fn into_owned(self) -> DbStr<'static> {
DbStr::into_owned(self)
}
}
impl IntoOwned for BitArray<'_> {
type Owned = BitArray<'static>;
#[inline]
fn into_owned(self) -> BitArray<'static> {
BitArray::into_owned(self)
}
}
impl<T: PackedPrim + 'static> IntoOwned for Packed<T> {
type Owned = Self;
#[inline]
fn into_owned(self) -> Self {
self
}
}
impl<T: IntoOwned> IntoOwned for Vec<T> {
type Owned = Vec<T::Owned>;
#[inline]
fn into_owned(self) -> Vec<T::Owned> {
self.into_iter().map(IntoOwned::into_owned).collect()
}
}
impl<T: IntoOwned> IntoOwned for List<T> {
type Owned = List<T::Owned>;
#[inline]
fn into_owned(self) -> List<T::Owned> {
List(self.0.into_owned())
}
}
impl<T: IntoOwned> IntoOwned for UnindexedList<T> {
type Owned = UnindexedList<T::Owned>;
#[inline]
fn into_owned(self) -> UnindexedList<T::Owned> {
UnindexedList(self.0.into_owned())
}
}
impl_identity_owned!(
crate::raw::EmptyBlock,
crate::raw::DatabaseVersion,
crate::raw::Rect,
crate::raw::Equipment,
crate::raw::Parameters,
);
impl IntoOwned for crate::raw::EventCommand<'_> {
type Owned = crate::raw::EventCommand<'static>;
fn into_owned(self) -> Self::Owned {
crate::raw::EventCommand {
code: self.code,
indent: self.indent,
string: self.string.into_owned(),
parameters: self.parameters,
}
}
}
impl IntoOwned for crate::raw::EventCommandList<'_> {
type Owned = crate::raw::EventCommandList<'static>;
fn into_owned(self) -> Self::Owned {
crate::raw::EventCommandList(self.0.into_owned())
}
}
impl IntoOwned for crate::raw::MoveCommand<'_> {
type Owned = crate::raw::MoveCommand<'static>;
fn into_owned(self) -> Self::Owned {
crate::raw::MoveCommand {
code: self.code,
string: self.string.into_owned(),
parameter_a: self.parameter_a,
parameter_b: self.parameter_b,
parameter_c: self.parameter_c,
}
}
}
impl IntoOwned for crate::raw::MoveCommandList<'_> {
type Owned = crate::raw::MoveCommandList<'static>;
fn into_owned(self) -> Self::Owned {
crate::raw::MoveCommandList(self.0.into_owned())
}
}
impl IntoOwned for crate::raw::StrList<'_> {
type Owned = crate::raw::StrList<'static>;
fn into_owned(self) -> Self::Owned {
crate::raw::StrList(self.0.into_owned())
}
}
impl IntoOwned for crate::rpg::TreeMap<'_> {
type Owned = crate::rpg::TreeMap<'static>;
fn into_owned(self) -> Self::Owned {
crate::rpg::TreeMap {
maps: self.maps.into_owned(),
tree_order: self.tree_order,
active_node: self.active_node,
start: self.start,
}
}
}