pdk_classy/hl/
flow.rs

1// Copyright (c) 2025, Salesforce, Inc.,
2// All rights reserved.
3// For full license text, see the LICENSE.txt file
4
5use super::early_response::Response;
6
7#[allow(unused)]
8use crate::hl::RequestData;
9
10/// Indicates whether the current Request will continue to upstream filters
11/// or if an early [`Response`] must break the current flow.
12/// This type is intended to be returned by Request filters.
13#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
14pub enum Flow<D> {
15    /// Represents that the Request flow must continue to upstream and carries user data to be
16    /// catched by [`RequestData::Continue`] in the Response filter.
17    Continue(D),
18
19    /// Represents that the Request flow must return an early [`Response`] breaking the flow
20    /// to upstream filters.
21    Break(Response),
22}
23
24/// A value-to-value conversion that consumes the input value and converts it in a [`Flow`].
25pub trait IntoFlow {
26    /// The user data type of the target [`Flow`].
27    type RequestData;
28
29    /// Converts this type into the [`Flow`] type.
30    fn into_flow(self) -> Flow<Self::RequestData>;
31}
32
33impl<D> IntoFlow for Flow<D> {
34    type RequestData = D;
35
36    fn into_flow(self) -> Flow<Self::RequestData> {
37        self
38    }
39}
40
41impl IntoFlow for () {
42    type RequestData = ();
43
44    fn into_flow(self) -> Flow<Self::RequestData> {
45        Flow::Continue(())
46    }
47}
48
49impl IntoFlow for Response {
50    type RequestData = ();
51
52    fn into_flow(self) -> Flow<Self::RequestData> {
53        Flow::Break(self)
54    }
55}