pub struct RootSupervisionReturn<T> { /* private fields */ }Expand description
A supervision result cannot be a naked technical code: failure consumes the original source receipt. Runtime retains its own physical ownership outside it.
ⓘ
use saddle_observability::RootSupervisionReturn;
use saddle_core::DiagnosticCode;
let _: RootSupervisionReturn<()> = RootSupervisionReturn::failed(DiagnosticCode::new("task.failed").unwrap());ⓘ
use saddle_observability::{RootSupervisionReturn, RootRequestFailure};
fn replay(f: RootRequestFailure) {
let _first = RootSupervisionReturn::<()>::failed(f);
let _second = RootSupervisionReturn::<()>::failed(f);
}Implementations§
Source§impl<T> RootSupervisionReturn<T>
impl<T> RootSupervisionReturn<T>
pub fn completed(value: T) -> Self
Sourcepub fn failed(failure: RootRequestFailure) -> Self
pub fn failed(failure: RootRequestFailure) -> Self
Examples found in repository?
examples/request_root_contract.rs (lines 128-130)
62fn main() {
63 // Storage contract exercise only. R0/A/R must reserve the exact layouts before
64 // this constructor is enabled in a real admitted or rejection path.
65 let mut publisher = RequestRootPublisher::create(
66 ContextLabel::checked("saddle").unwrap(),
67 ContextFact::NotEstablished,
68 )
69 .unwrap();
70 let root = publisher.reference();
71 let early = root.view(
72 RequestLocalFacts::new(RequestViewPhase::Reading).with_task(ContextFact::Present(17)),
73 );
74 let read_error = std::io::Error::from(std::io::ErrorKind::UnexpectedEof);
75 let early_failure = RootDiagnosticScope::new(&early, None).source_error(
76 &read_error,
77 DiagnosticStage::RequestDecode,
78 RootRequestEvent::Ingress,
79 RootOutcomeFacts::default(),
80 );
81 let event = EventContext::new(
82 RequestIdentity::new("request-a").unwrap(),
83 RouteIdentity::new("example.live").unwrap(),
84 1,
85 )
86 .unwrap();
87 assert!(
88 publisher
89 .publish(
90 request_identity_group(
91 &call("0", 1, "entry", "app", "example.live"),
92 &event,
93 ContextFact::Present(ContextLabel::checked("local").unwrap())
94 )
95 .unwrap()
96 )
97 .is_ok()
98 );
99 let active = early
100 .refresh(&root)
101 .unwrap()
102 .with_phase(RequestViewPhase::Handler);
103 // Formal Boundary style: real child Call and event originate from its actual
104 // ProfuseContract request. Obs validates rather than inventing a child RPC.
105 let child_event = EventContext::new(
106 RequestIdentity::new("request-a").unwrap(),
107 RouteIdentity::new("receipt.invoke").unwrap(),
108 1,
109 )
110 .unwrap();
111 let child = request_child_view(
112 &active,
113 &call("0.1", 2, "local", "profusecontract", "invoke"),
114 &child_event,
115 )
116 .unwrap();
117 assert!(active.same_request(&child));
118 let (_, issuer) = DbPhysicalDispositionIssuer::issue().into_startup_and_request_issuer();
119 let (request, execution) = issuer.issue_request().unwrap();
120 // Real D passes &sqlx::Error here before driver_ref/business mapping. This
121 // standalone example uses the standard Error contract, with no DB dependency.
122 let raw_error = std::io::Error::new(
123 std::io::ErrorKind::PermissionDenied,
124 "original driver description",
125 );
126 let db_failure = database_source(&active, &request, &execution, None, &raw_error);
127 drop(raw_error);
128 let supervised = RootSupervisionReturn::<()>::failed(
129 db_failure.map_classification(DiagnosticCode::new("handler.failed").unwrap()),
130 );
131 let failure = supervised.consume().err().unwrap();
132 // Public projections contain no source body or root. Real Runtime must also
133 // finish the original physical pair, then drop all views before settlement.
134 let public = failure
135 .finish(&active, None, RootOutcomeFacts::default())
136 .ok()
137 .unwrap();
138 let early_public = early_failure
139 .finish(&active, None, RootOutcomeFacts::default())
140 .ok()
141 .unwrap();
142 let observer = Observer::with_writer(ObserverConfig::default(), std::io::sink()).unwrap();
143 let completed = RootDiagnosticScope::new(&active, None)
144 .start_stage(&observer, RootRequestEvent::Response)
145 .finish_nonfailure(RootOutcomeFacts {
146 axes: DiagnosticOutcomeAxes {
147 operation: OperationOutcome::Succeeded,
148 ..Default::default()
149 },
150 ..Default::default()
151 })
152 .ok()
153 .unwrap();
154 assert_eq!(completed, DiagnosticSubmission::OutputUnavailable);
155 assert_eq!(
156 RootDiagnosticScope::new(&active, None).ordinary(
157 &observer,
158 RootRequestEvent::Handler,
159 RootOutcomeFacts::default()
160 ),
161 DiagnosticSubmission::Enqueued
162 );
163 drop((publisher, root, early, active, child));
164 assert_eq!(
165 public.source_submission(),
166 DiagnosticSubmission::OutputUnavailable
167 );
168 assert_eq!(
169 early_public.terminal_submission(),
170 DiagnosticSubmission::OutputUnavailable
171 );
172 for (name, (payload, shared)) in ["root", "view", "child"]
173 .into_iter()
174 .zip(saddle_core::request_context::request_context_layouts())
175 {
176 println!(
177 "layout {name}: payload={} align={} arc_allocation={} arc_align={}",
178 payload.size(),
179 payload.align(),
180 shared.size(),
181 shared.align()
182 );
183 }
184 println!(
185 "layout receipt={} public={} root_ref={} view_ref={} identity_input={} bounded_detail={} borrowed_stage={}",
186 size_of::<RootRequestFailure>(),
187 size_of::<PublicRequestFailure>(),
188 size_of::<RequestRootRef>(),
189 size_of::<RequestExecutionView>(),
190 size_of::<RequestIdentityGroup>(),
191 size_of::<BoundedDiagnostic>(),
192 size_of::<RootActiveStage<'static>>()
193 );
194 println!("C consumer contract GO; production reservation/lifecycle NOT_RUN");
195 let layout = saddle_observability::root_diagnostic::request_logging_layouts();
196 let (stream, cycle, payload) = saddle_observability::root_diagnostic::original_capture_layout();
197 println!(
198 "layout original_stream={} align={} cycle_detector={} align={} payload_limit={} total_content_limit=none",
199 stream.size(),
200 stream.align(),
201 cycle.size(),
202 cycle.align(),
203 payload
204 );
205 println!(
206 "layout source_frame={} source_record={} emergency_packet={} emergency_slots={} ordinary_command={} ordinary_payload_max={}",
207 layout.source_frame.size(),
208 layout.source_record.size(),
209 layout.emergency_packet.size(),
210 layout.emergency_slots,
211 layout.ordinary_command.size(),
212 layout.ordinary_encoded_bytes_max
213 );
214}Sourcepub fn consume(self) -> Result<T, RootRequestFailure>
pub fn consume(self) -> Result<T, RootRequestFailure>
Examples found in repository?
examples/request_root_contract.rs (line 131)
62fn main() {
63 // Storage contract exercise only. R0/A/R must reserve the exact layouts before
64 // this constructor is enabled in a real admitted or rejection path.
65 let mut publisher = RequestRootPublisher::create(
66 ContextLabel::checked("saddle").unwrap(),
67 ContextFact::NotEstablished,
68 )
69 .unwrap();
70 let root = publisher.reference();
71 let early = root.view(
72 RequestLocalFacts::new(RequestViewPhase::Reading).with_task(ContextFact::Present(17)),
73 );
74 let read_error = std::io::Error::from(std::io::ErrorKind::UnexpectedEof);
75 let early_failure = RootDiagnosticScope::new(&early, None).source_error(
76 &read_error,
77 DiagnosticStage::RequestDecode,
78 RootRequestEvent::Ingress,
79 RootOutcomeFacts::default(),
80 );
81 let event = EventContext::new(
82 RequestIdentity::new("request-a").unwrap(),
83 RouteIdentity::new("example.live").unwrap(),
84 1,
85 )
86 .unwrap();
87 assert!(
88 publisher
89 .publish(
90 request_identity_group(
91 &call("0", 1, "entry", "app", "example.live"),
92 &event,
93 ContextFact::Present(ContextLabel::checked("local").unwrap())
94 )
95 .unwrap()
96 )
97 .is_ok()
98 );
99 let active = early
100 .refresh(&root)
101 .unwrap()
102 .with_phase(RequestViewPhase::Handler);
103 // Formal Boundary style: real child Call and event originate from its actual
104 // ProfuseContract request. Obs validates rather than inventing a child RPC.
105 let child_event = EventContext::new(
106 RequestIdentity::new("request-a").unwrap(),
107 RouteIdentity::new("receipt.invoke").unwrap(),
108 1,
109 )
110 .unwrap();
111 let child = request_child_view(
112 &active,
113 &call("0.1", 2, "local", "profusecontract", "invoke"),
114 &child_event,
115 )
116 .unwrap();
117 assert!(active.same_request(&child));
118 let (_, issuer) = DbPhysicalDispositionIssuer::issue().into_startup_and_request_issuer();
119 let (request, execution) = issuer.issue_request().unwrap();
120 // Real D passes &sqlx::Error here before driver_ref/business mapping. This
121 // standalone example uses the standard Error contract, with no DB dependency.
122 let raw_error = std::io::Error::new(
123 std::io::ErrorKind::PermissionDenied,
124 "original driver description",
125 );
126 let db_failure = database_source(&active, &request, &execution, None, &raw_error);
127 drop(raw_error);
128 let supervised = RootSupervisionReturn::<()>::failed(
129 db_failure.map_classification(DiagnosticCode::new("handler.failed").unwrap()),
130 );
131 let failure = supervised.consume().err().unwrap();
132 // Public projections contain no source body or root. Real Runtime must also
133 // finish the original physical pair, then drop all views before settlement.
134 let public = failure
135 .finish(&active, None, RootOutcomeFacts::default())
136 .ok()
137 .unwrap();
138 let early_public = early_failure
139 .finish(&active, None, RootOutcomeFacts::default())
140 .ok()
141 .unwrap();
142 let observer = Observer::with_writer(ObserverConfig::default(), std::io::sink()).unwrap();
143 let completed = RootDiagnosticScope::new(&active, None)
144 .start_stage(&observer, RootRequestEvent::Response)
145 .finish_nonfailure(RootOutcomeFacts {
146 axes: DiagnosticOutcomeAxes {
147 operation: OperationOutcome::Succeeded,
148 ..Default::default()
149 },
150 ..Default::default()
151 })
152 .ok()
153 .unwrap();
154 assert_eq!(completed, DiagnosticSubmission::OutputUnavailable);
155 assert_eq!(
156 RootDiagnosticScope::new(&active, None).ordinary(
157 &observer,
158 RootRequestEvent::Handler,
159 RootOutcomeFacts::default()
160 ),
161 DiagnosticSubmission::Enqueued
162 );
163 drop((publisher, root, early, active, child));
164 assert_eq!(
165 public.source_submission(),
166 DiagnosticSubmission::OutputUnavailable
167 );
168 assert_eq!(
169 early_public.terminal_submission(),
170 DiagnosticSubmission::OutputUnavailable
171 );
172 for (name, (payload, shared)) in ["root", "view", "child"]
173 .into_iter()
174 .zip(saddle_core::request_context::request_context_layouts())
175 {
176 println!(
177 "layout {name}: payload={} align={} arc_allocation={} arc_align={}",
178 payload.size(),
179 payload.align(),
180 shared.size(),
181 shared.align()
182 );
183 }
184 println!(
185 "layout receipt={} public={} root_ref={} view_ref={} identity_input={} bounded_detail={} borrowed_stage={}",
186 size_of::<RootRequestFailure>(),
187 size_of::<PublicRequestFailure>(),
188 size_of::<RequestRootRef>(),
189 size_of::<RequestExecutionView>(),
190 size_of::<RequestIdentityGroup>(),
191 size_of::<BoundedDiagnostic>(),
192 size_of::<RootActiveStage<'static>>()
193 );
194 println!("C consumer contract GO; production reservation/lifecycle NOT_RUN");
195 let layout = saddle_observability::root_diagnostic::request_logging_layouts();
196 let (stream, cycle, payload) = saddle_observability::root_diagnostic::original_capture_layout();
197 println!(
198 "layout original_stream={} align={} cycle_detector={} align={} payload_limit={} total_content_limit=none",
199 stream.size(),
200 stream.align(),
201 cycle.size(),
202 cycle.align(),
203 payload
204 );
205 println!(
206 "layout source_frame={} source_record={} emergency_packet={} emergency_slots={} ordinary_command={} ordinary_payload_max={}",
207 layout.source_frame.size(),
208 layout.source_record.size(),
209 layout.emergency_packet.size(),
210 layout.emergency_slots,
211 layout.ordinary_command.size(),
212 layout.ordinary_encoded_bytes_max
213 );
214}Auto Trait Implementations§
impl<T> Freeze for RootSupervisionReturn<T>
impl<T> RefUnwindSafe for RootSupervisionReturn<T>
impl<T> Send for RootSupervisionReturn<T>
impl<T> Sync for RootSupervisionReturn<T>
impl<T> Unpin for RootSupervisionReturn<T>
impl<T> UnsafeUnpin for RootSupervisionReturn<T>
impl<T> UnwindSafe for RootSupervisionReturn<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more