Add newlines and reformat for better code quality

This commit is contained in:
Michael Mikovsky
2026-04-24 14:27:55 -06:00
parent fc8638d014
commit 11674bae8f
12 changed files with 43 additions and 25 deletions
+1 -1
View File
@@ -212,7 +212,7 @@ where
fn align_section(bytes: &[u8]) -> AlignedVec { fn align_section(bytes: &[u8]) -> AlignedVec {
if bytes.as_ptr().align_offset(16) == 0 { if bytes.as_ptr().align_offset(16) == 0 {
// Still need to return AlignedVec for the API, but maybe we can avoid // Still need to return AlignedVec for the API, but maybe we can avoid
// some overhead. Actually, AlignedVec is just a wrapper around Vec. // some overhead. Actually, AlignedVec is just a wrapper around Vec.
} }
let mut aligned = AlignedVec::with_capacity(bytes.len()); let mut aligned = AlignedVec::with_capacity(bytes.len());
+4 -1
View File
@@ -81,7 +81,10 @@ fn header_and_call_validation_reject_invalid_combinations() {
#[test] #[test]
fn procedure_validation_accepts_introspection_and_rejects_bad_shapes() { fn procedure_validation_accepts_introspection_and_rejects_bad_shapes() {
assert_eq!(validate_procedure_id(""), Ok(())); assert_eq!(validate_procedure_id(""), Ok(()));
assert_eq!(validate_procedure_id("unshell.echo.v01.alpha.invoke"), Ok(())); assert_eq!(
validate_procedure_id("unshell.echo.v01.alpha.invoke"),
Ok(())
);
assert_eq!( assert_eq!(
validate_procedure_id("contains spaces"), validate_procedure_id("contains spaces"),
Err(ValidationError::ProcedureId( Err(ValidationError::ProcedureId(
+5 -1
View File
@@ -80,7 +80,11 @@ fn protocol_endpoint_introspection_returns_leaf_summary() {
assert!(outcome.forwards.is_empty()); assert!(outcome.forwards.is_empty());
assert_eq!(outcome.events.len(), 1); assert_eq!(outcome.events.len(), 1);
let LocalEvent::Data { header, message: response } = &outcome.events[0] else { let LocalEvent::Data {
header,
message: response,
} = &outcome.events[0]
else {
panic!("expected local data event"); panic!("expected local data event");
}; };
assert_eq!(header.packet_type, PacketType::Data); assert_eq!(header.packet_type, PacketType::Data);
+2 -2
View File
@@ -8,8 +8,8 @@ use alloc::{string::String, vec::Vec};
use super::{ use super::{
FrameBytes, FrameCodec, LeafIntrospection, LeafIntrospectionSummary, FrameBytes, FrameCodec, LeafIntrospection, LeafIntrospectionSummary,
tree::{ tree::{
ActiveHook, Endpoint, EndpointError, EndpointOutcome, HookConflict, HookKey, HookTable, Ingress, ActiveHook, Endpoint, EndpointError, EndpointOutcome, HookConflict, HookKey, HookTable,
LeafNode, LeafSpec, PendingHook, RouteProvider, Ingress, LeafNode, LeafSpec, PendingHook, RouteProvider,
}, },
}; };
+3 -2
View File
@@ -12,8 +12,9 @@ use alloc::{
}; };
use core::fmt; use core::fmt;
use crate::protocol::{CallMessage, DataMessage, FaultMessage, FrameBytes, FrameError, PacketHeader, use crate::protocol::{
ValidationError}; CallMessage, DataMessage, FaultMessage, FrameBytes, FrameError, PacketHeader, ValidationError,
};
use super::super::{HookTable, RouteDecision}; use super::super::{HookTable, RouteDecision};
+5 -7
View File
@@ -5,10 +5,12 @@
use alloc::{string::String, vec}; use alloc::{string::String, vec};
use crate::protocol::{DataMessage, FaultMessage, PacketHeader, PacketType, ProtocolFault, encode_packet}; use crate::protocol::{
DataMessage, FaultMessage, PacketHeader, PacketType, ProtocolFault, encode_packet,
};
use super::core::{EndpointError, EndpointOutcome, Ingress, LocalEvent, ProtocolEndpoint};
use super::super::{HookKey, RouteDecision, route_destination}; use super::super::{HookKey, RouteDecision, route_destination};
use super::core::{EndpointError, EndpointOutcome, Ingress, LocalEvent, ProtocolEndpoint};
impl ProtocolEndpoint { impl ProtocolEndpoint {
/// Emits a protocol fault only when the original call declared a response hook. /// Emits a protocol fault only when the original call declared a response hook.
@@ -167,11 +169,7 @@ impl ProtocolEndpoint {
/// Rationale: this looks backwards at first because parent ingress accepts /// Rationale: this looks backwards at first because parent ingress accepts
/// non-local source paths. That is required for multi-hop routing, where a /// non-local source paths. That is required for multi-hop routing, where a
/// parent forwards traffic originating from ancestors or siblings. /// parent forwards traffic originating from ancestors or siblings.
pub(crate) fn valid_source_for_ingress( pub(crate) fn valid_source_for_ingress(&self, ingress: &Ingress, src_path: &[String]) -> bool {
&self,
ingress: &Ingress,
src_path: &[String],
) -> bool {
match ingress { match ingress {
Ingress::Parent => { Ingress::Parent => {
if src_path.len() < self.path.len() { if src_path.len() < self.path.len() {
+1 -1
View File
@@ -11,8 +11,8 @@ use crate::protocol::{
PacketHeader, PacketType, ProtocolFault, encode_packet, PacketHeader, PacketType, ProtocolFault, encode_packet,
}; };
use super::core::{EndpointError, EndpointOutcome, ProtocolEndpoint};
use super::super::HookKey; use super::super::HookKey;
use super::core::{EndpointError, EndpointOutcome, ProtocolEndpoint};
impl ProtocolEndpoint { impl ProtocolEndpoint {
/// Handles the reserved introspection procedure. /// Handles the reserved introspection procedure.
+2 -2
View File
@@ -17,6 +17,6 @@ mod introspection;
mod receive; mod receive;
pub use core::{ pub use core::{
ChildRoute, ConnectionState, Endpoint, EndpointError, EndpointOutcome, Ingress, ChildRoute, ConnectionState, Endpoint, EndpointError, EndpointOutcome, Ingress, LeafBehavior,
LeafBehavior, LeafSpec, LocalEvent, ProtocolEndpoint, LeafSpec, LocalEvent, ProtocolEndpoint,
}; };
+13 -3
View File
@@ -10,8 +10,10 @@ use crate::protocol::{
introspection::INTROSPECTION_PROCEDURE_ID, validate_call, validate_header, introspection::INTROSPECTION_PROCEDURE_ID, validate_call, validate_header,
}; };
use super::core::{Endpoint, EndpointError, EndpointOutcome, Ingress, LocalEvent, ProtocolEndpoint};
use super::super::{HookKey, PendingHook, RouteDecision}; use super::super::{HookKey, PendingHook, RouteDecision};
use super::core::{
Endpoint, EndpointError, EndpointOutcome, Ingress, LocalEvent, ProtocolEndpoint,
};
impl ProtocolEndpoint { impl ProtocolEndpoint {
/// Handles a locally delivered `Call` packet after routing selected `Local`. /// Handles a locally delivered `Call` packet after routing selected `Local`.
@@ -49,7 +51,11 @@ impl ProtocolEndpoint {
Some(leaf_name) => self Some(leaf_name) => self
.leaves .leaves
.get(leaf_name) .get(leaf_name)
.map(|leaf| leaf.procedures.iter().any(|procedure| procedure == &message.procedure_id)) .map(|leaf| {
leaf.procedures
.iter()
.any(|procedure| procedure == &message.procedure_id)
})
.unwrap_or(false), .unwrap_or(false),
None => self.endpoint_procedures.contains(&message.procedure_id), None => self.endpoint_procedures.contains(&message.procedure_id),
}; };
@@ -71,7 +77,11 @@ impl ProtocolEndpoint {
self.hooks.activate_pending(key, header.src_path.clone()); self.hooks.activate_pending(key, header.src_path.clone());
} }
match header.dst_leaf.as_ref().and_then(|name| self.leaves.get(name)) { match header
.dst_leaf
.as_ref()
.and_then(|name| self.leaves.get(name))
{
Some(leaf) if leaf.behavior == super::core::LeafBehavior::Echo && key.is_some() => { Some(leaf) if leaf.behavior == super::core::LeafBehavior::Echo && key.is_some() => {
let hook = message.response_hook.expect("synchronized"); let hook = message.response_hook.expect("synchronized");
let response = DataMessage { let response = DataMessage {
+2 -2
View File
@@ -5,8 +5,8 @@ mod hook;
mod routing; mod routing;
pub use endpoint::{ pub use endpoint::{
ChildRoute, ConnectionState, Endpoint, EndpointError, EndpointOutcome, Ingress, ChildRoute, ConnectionState, Endpoint, EndpointError, EndpointOutcome, Ingress, LeafBehavior,
LeafBehavior, LeafSpec, LocalEvent, ProtocolEndpoint, LeafSpec, LocalEvent, ProtocolEndpoint,
}; };
pub use hook::{ActiveHook, HookConflict, HookKey, HookTable, PendingHook}; pub use hook::{ActiveHook, HookConflict, HookKey, HookTable, PendingHook};
pub use routing::{ pub use routing::{
+1 -2
View File
@@ -87,8 +87,7 @@ pub trait RouteProvider {
) -> RouteDecision ) -> RouteDecision
where where
I: IntoIterator, I: IntoIterator,
I::Item: AsRef<[String]>, I::Item: AsRef<[String]>;
;
} }
/// Default routing implementation using the protocol's longest-prefix rule. /// Default routing implementation using the protocol's longest-prefix rule.
+4 -1
View File
@@ -69,7 +69,10 @@ pub fn validate_procedure_id(procedure_id: &str) -> Result<(), ValidationError>
)); ));
} }
if !procedure_id.chars().all(|ch| ch.is_ascii_alphanumeric() || ch == '_' || ch == '.') { if !procedure_id
.chars()
.all(|ch| ch.is_ascii_alphanumeric() || ch == '_' || ch == '.')
{
return Err(ValidationError::ProcedureId( return Err(ValidationError::ProcedureId(
"procedure identifier should use alphanumeric characters, dots, and underscores", "procedure identifier should use alphanumeric characters, dots, and underscores",
)); ));