Repository: bevyengine/bevy
File: crates/bevy_ecs/src/system/builder.rs (Rust)

Code before:
                func,
                meta: SystemMeta::new::<Func>(),
            },
        }
    }
}

enum BuilderSystemInner<Marker, In, Out, Func, Builder>
where
    Func: SystemParamFunction<Marker>,
    Builder: SystemParamBuilder<Func::Param>,
{
    /// A properly initialized system whose state has been constructed
    Initialized {
        system: FunctionSystem<Marker, In, Out, Func>,
    },
    /// An uninitialized system, whose state hasn't been constructed from
    /// the param builder yet
    Uninitialized {
        builder: Builder,
        func: Func,
        meta: SystemMeta,
    },
    // This only exists as a variant to use with `mem::replace` in `initialize`.
    // If this state is ever observed outside `initialize`, then a `panic!`
    // interrupted initialization, leaving this system in an invalid state.
    Invalid,
}

impl<Marker, In, Out, Func, Builder> System for BuilderSystem<Marker, In, Out, Func, Builder>
where
    Marker: 'static,
    In: SystemInput + 'static,
    Out: 'static,
    Func: SystemParamFunction<Marker, In: FromInput<In>, Out: IntoResult<Out>>,
    Builder: SystemParamBuilder<Func::Param> + Send + Sync + 'static,
{
    type In = In;

    type Out = Out;

    #[inline]
    fn name(&self) -> DebugName {
        match &self.inner {
            BuilderSystemInner::Initialized { system } => system.name(),
            BuilderSystemInner::Uninitialized { meta, .. } => meta.name().clone(),
            BuilderSystemInner::Invalid => unreachable!(),
        }
    }

    #[inline]

Review comment (suggestion):
Any reason not to make these doc comments?

```suggestion
    /// This only exists as a variant to use with `mem::replace` in `initialize`.
    /// If this state is ever observed outside `initialize`, then a `panic!`
    /// interrupted initialization, leaving this system in an invalid state.
```

Code after:
    Builder: SystemParamBuilder<Func::Param> + Send + Sync + 'static,
{
    type System = BuilderSystem<Marker, In, Out, Func, Builder>;

    fn into_system(this: Self) -> Self::System {
        BuilderSystem::new(this.builder, this.func)
    }
}

/// A [`System`] created from a [`SystemParamBuilder`] whose state is not
/// initialized until the first run.
pub struct BuilderSystem<Marker, In, Out, Func, Builder>
where
    Func: SystemParamFunction<Marker>,
    Builder: SystemParamBuilder<Func::Param>,
{
    inner: BuilderSystemInner<Marker, In, Out, Func, Builder>,
}

impl<Marker, In, Out, Func, Builder> BuilderSystem<Marker, In, Out, Func, Builder>
where
    Func: SystemParamFunction<Marker>,
    Builder: SystemParamBuilder<Func::Param>,
{
    /// Returns a new `BuilderSystem` given a system param builder and a system function
    pub fn new(builder: Builder, func: Func) -> Self {
        Self {
            inner: BuilderSystemInner::Uninitialized {
                builder,
                func,
                meta: SystemMeta::new::<Func>(),
            },
        }
    }
}

enum BuilderSystemInner<Marker, In, Out, Func, Builder>
where
    Func: SystemParamFunction<Marker>,
    Builder: SystemParamBuilder<Func::Param>,
{
    /// A properly initialized system whose state has been constructed
    Initialized {
        system: FunctionSystem<Marker, In, Out, Func>,
    },
    /// An uninitialized system, whose state hasn't been constructed from
    /// the param builder yet
    Uninitialized {
        builder: Builder,
        func: Func,
        meta: SystemMeta,