pdk-classy 1.9.1-alpha.2

PDK Classy
Documentation
// Copyright (c) 2026, Salesforce, Inc.,
// All rights reserved.
// For full license text, see the LICENSE.txt file

use super::early_response::Response;

#[allow(unused)]
use crate::hl::RequestData;

/// Indicates whether the current Request will continue to upstream filters
/// or if an early [`Response`] must break the current flow.
/// This type is intended to be returned by Request filters.
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
pub enum Flow<D> {
    /// Represents that the Request flow must continue to upstream and carries user data to be
    /// catched by [`RequestData::Continue`] in the Response filter.
    Continue(D),

    /// Represents that the Request flow must return an early [`Response`] breaking the flow
    /// to upstream filters.
    Break(Response),
}

/// A value-to-value conversion that consumes the input value and converts it in a [`Flow`].
pub trait IntoFlow {
    /// The user data type of the target [`Flow`].
    type RequestData;

    /// Converts this type into the [`Flow`] type.
    fn into_flow(self) -> Flow<Self::RequestData>;
}

impl<D> IntoFlow for Flow<D> {
    type RequestData = D;

    fn into_flow(self) -> Flow<Self::RequestData> {
        self
    }
}

impl IntoFlow for () {
    type RequestData = ();

    fn into_flow(self) -> Flow<Self::RequestData> {
        Flow::Continue(())
    }
}

impl IntoFlow for Response {
    type RequestData = ();

    fn into_flow(self) -> Flow<Self::RequestData> {
        Flow::Break(self)
    }
}