mirror of https://github.com/hannobraun/Fornjot
Make `Insert` more flexible
This commit is contained in:
parent
761f9eff14
commit
da5bd11057
|
@ -69,7 +69,7 @@ pub trait TransformObject: Sized {
|
||||||
|
|
||||||
impl<T> TransformObject for Handle<T>
|
impl<T> TransformObject for Handle<T>
|
||||||
where
|
where
|
||||||
T: Clone + Insert + TransformObject + 'static,
|
T: Clone + Insert<Inserted = Handle<T>> + TransformObject + 'static,
|
||||||
{
|
{
|
||||||
fn transform_with_cache(
|
fn transform_with_cache(
|
||||||
self,
|
self,
|
||||||
|
|
|
@ -12,15 +12,23 @@ use crate::{
|
||||||
/// This is the only primitive operation that is directly understood by
|
/// This is the only primitive operation that is directly understood by
|
||||||
/// `Service<Objects>`. All other operations are built on top of it.
|
/// `Service<Objects>`. All other operations are built on top of it.
|
||||||
pub trait Insert: Sized {
|
pub trait Insert: Sized {
|
||||||
|
/// The type of `Self`, once it has been inserted
|
||||||
|
///
|
||||||
|
/// Usually this is just `Handle<Self>`, but there are some more complex
|
||||||
|
/// cases where this type needs to be customized.
|
||||||
|
type Inserted;
|
||||||
|
|
||||||
/// Insert the object into its respective store
|
/// Insert the object into its respective store
|
||||||
fn insert(self, services: &mut Services) -> Handle<Self>;
|
fn insert(self, services: &mut Services) -> Self::Inserted;
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_insert {
|
macro_rules! impl_insert {
|
||||||
($($ty:ty, $store:ident;)*) => {
|
($($ty:ty, $store:ident;)*) => {
|
||||||
$(
|
$(
|
||||||
impl Insert for $ty {
|
impl Insert for $ty {
|
||||||
fn insert(self, services: &mut Services) -> Handle<Self> {
|
type Inserted = Handle<Self>;
|
||||||
|
|
||||||
|
fn insert(self, services: &mut Services) -> Self::Inserted {
|
||||||
let handle = services.objects.$store.reserve();
|
let handle = services.objects.$store.reserve();
|
||||||
let object = (handle.clone(), self).into();
|
let object = (handle.clone(), self).into();
|
||||||
services.insert_object(object);
|
services.insert_object(object);
|
||||||
|
|
Loading…
Reference in New Issue