diff --git a/crux_cli/fixtures-counter-actual.json b/crux_cli/fixtures-counter-actual.json index 722604cdc..74a250aaf 100644 --- a/crux_cli/fixtures-counter-actual.json +++ b/crux_cli/fixtures-counter-actual.json @@ -40,15 +40,89 @@ } } }, - "ServerSentEvents": { + "HttpError": { + "ENUM": { + "0": { + "Url": { + "NEWTYPE": "STR" + } + }, + "1": { + "Io": { + "NEWTYPE": "STR" + } + }, + "2": { + "Timeout": "UNIT" + } + } + }, + "HttpHeader": { + "STRUCT": [ + { + "name": "STR" + }, + { + "value": "STR" + } + ] + }, + "HttpRequest": { + "STRUCT": [ + { + "method": "STR" + }, + { + "url": "STR" + }, + { + "headers": { + "SEQ": { + "TYPENAME": "HttpHeader" + } + } + }, + { + "body": "BYTES" + } + ] + }, + "HttpResponse": { "STRUCT": [ { - "context": { - "TYPENAME": "crux_core::capability::CapabilityContext" + "status": "U16" + }, + { + "headers": { + "SEQ": { + "TYPENAME": "HttpHeader" + } } + }, + { + "body": "BYTES" } ] }, + "HttpResult": { + "ENUM": { + "0": { + "Ok": { + "NEWTYPE": { + "TYPENAME": "HttpResponse" + } + } + }, + "1": { + "Err": { + "NEWTYPE": { + "TYPENAME": "crate::HttpError" + } + } + } + } + }, + "RenderOperation": "UNITSTRUCT", "SseRequest": { "STRUCT": [ { diff --git a/crux_cli/src/codegen/filter.rs b/crux_cli/src/codegen/filter.rs index 8d96c4168..132fc124b 100644 --- a/crux_cli/src/codegen/filter.rs +++ b/crux_cli/src/codegen/filter.rs @@ -122,11 +122,15 @@ ascent! { // set of all the edges we are interested in relation edge(ItemNode, ItemNode); - // root fields + // roots that are unit structs + edge(root, root) <-- + root(root), + is_struct(root); + // roots that have fields edge(root, field) <-- root(root), field(root, field); - // root variants + // roots that have variants edge(root, variant) <-- root(root), variant(root, variant); diff --git a/crux_cli/src/codegen/formatter.rs b/crux_cli/src/codegen/formatter.rs index 66df3a3d7..261ed7a76 100644 --- a/crux_cli/src/codegen/formatter.rs +++ b/crux_cli/src/codegen/formatter.rs @@ -119,7 +119,18 @@ fn make_format(field: &ItemNode, all_fields: &Vec) -> Option Some(Indexed { index: index as u32, - value: type_.into(), + value: { + if let Some((_whole, serde_with)) = &field.0.attrs.iter().find_map(|attr| { + lazy_regex::regex_captures!(r#"\[serde\(with\s*=\s*"(\w+)"\)\]"#, attr) + }) { + match *serde_with { + "serde_bytes" => Format::Bytes, // e.g. HttpRequest.body, HttpResponse.body + _ => todo!(), + } + } else { + type_.into() + } + }, }), _ => None, } diff --git a/crux_cli/src/codegen/node.rs b/crux_cli/src/codegen/node.rs index 61ad405e6..8fbd49384 100644 --- a/crux_cli/src/codegen/node.rs +++ b/crux_cli/src/codegen/node.rs @@ -80,11 +80,12 @@ impl ItemNode { } pub fn is_subset(&self) -> bool { - self.is_struct() + // from most likely to least likely + self.is_impl() || self.is_struct_field() - || self.is_enum() || self.is_enum_variant() - || self.is_impl() + || self.is_struct() + || self.is_enum() || self.is_associated_type() }