diff --git a/Cargo.lock b/Cargo.lock index c01748c..964a19e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1198,7 +1198,7 @@ dependencies = [ "progenitor-macro", "project-root", "rand", - "regress 0.5.0", + "regress", "reqwest", "schemars", "serde", @@ -1343,15 +1343,6 @@ version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" -[[package]] -name = "regress" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a92ff21fe8026ce3f2627faaf43606f0b67b014dbc9ccf027181a804f75d92e" -dependencies = [ - "memchr", -] - [[package]] name = "regress" version = "0.5.0" @@ -2055,7 +2046,7 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "typify" version = "0.0.11-dev" -source = "git+https://github.com/oxidecomputer/typify#d1cae0f7d5115782c9557a46396dae786ad5f592" +source = "git+https://github.com/oxidecomputer/typify#b35e5c06e7e67bfc350840d00bf86a19bff662a7" dependencies = [ "typify-impl", "typify-macro", @@ -2064,14 +2055,13 @@ dependencies = [ [[package]] name = "typify-impl" version = "0.0.11-dev" -source = "git+https://github.com/oxidecomputer/typify#d1cae0f7d5115782c9557a46396dae786ad5f592" +source = "git+https://github.com/oxidecomputer/typify#b35e5c06e7e67bfc350840d00bf86a19bff662a7" dependencies = [ "heck", "log", "proc-macro2", "quote", - "regress 0.4.1", - "rustfmt-wrapper", + "regress", "schemars", "serde_json", "syn", @@ -2082,7 +2072,7 @@ dependencies = [ [[package]] name = "typify-macro" version = "0.0.11-dev" -source = "git+https://github.com/oxidecomputer/typify#d1cae0f7d5115782c9557a46396dae786ad5f592" +source = "git+https://github.com/oxidecomputer/typify#b35e5c06e7e67bfc350840d00bf86a19bff662a7" dependencies = [ "proc-macro2", "quote", diff --git a/progenitor-impl/tests/output/nexus-builder-tagged.out b/progenitor-impl/tests/output/nexus-builder-tagged.out index 8f9a677..473f430 100644 --- a/progenitor-impl/tests/output/nexus-builder-tagged.out +++ b/progenitor-impl/tests/output/nexus-builder-tagged.out @@ -423,6 +423,54 @@ pub mod types { } } + impl From for Datum { + fn from(value: bool) -> Self { + Self::Bool(value) + } + } + + impl From for Datum { + fn from(value: i64) -> Self { + Self::I64(value) + } + } + + impl From for Datum { + fn from(value: f64) -> Self { + Self::F64(value) + } + } + + impl From> for Datum { + fn from(value: Vec) -> Self { + Self::Bytes(value) + } + } + + impl From for Datum { + fn from(value: Cumulativeint64) -> Self { + Self::CumulativeI64(value) + } + } + + impl From for Datum { + fn from(value: Cumulativedouble) -> Self { + Self::CumulativeF64(value) + } + } + + impl From for Datum { + fn from(value: Histogramint64) -> Self { + Self::HistogramI64(value) + } + } + + impl From for Datum { + fn from(value: Histogramdouble) -> Self { + Self::HistogramF64(value) + } + } + ///The type of an individual datum of a metric. #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] pub enum DatumType { @@ -1998,6 +2046,12 @@ pub mod types { } } + impl From> for InstanceNetworkInterfaceAttachment { + fn from(value: Vec) -> Self { + Self::Create(value) + } + } + ///A single page of results #[derive(Clone, Debug, Deserialize, Serialize)] pub struct InstanceResultsPage { @@ -2261,6 +2315,18 @@ pub mod types { } } + impl From for IpNet { + fn from(value: Ipv4Net) -> Self { + Self::V4(value) + } + } + + impl From for IpNet { + fn from(value: Ipv6Net) -> Self { + Self::V6(value) + } + } + ///Identity-related metadata that's included in nearly all public API /// objects #[derive(Clone, Debug, Deserialize, Serialize)] @@ -2407,6 +2473,18 @@ pub mod types { } } + impl From for IpRange { + fn from(value: Ipv4Range) -> Self { + Self::V4(value) + } + } + + impl From for IpRange { + fn from(value: Ipv6Range) -> Self { + Self::V6(value) + } + } + ///An IPv4 subnet, including prefix and subnet mask #[derive(Clone, Debug, Serialize)] pub struct Ipv4Net(String); @@ -2886,6 +2964,18 @@ pub mod types { } } + impl From for NameOrId { + fn from(value: uuid::Uuid) -> Self { + Self::Id(value) + } + } + + impl From for NameOrId { + fn from(value: Name) -> Self { + Self::Name(value) + } + } + ///Supported set of sort modes for scanning by name or id #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] pub enum NameOrIdSortMode { @@ -3934,6 +4024,18 @@ pub mod types { } } + impl From for RouteDestination { + fn from(value: std::net::IpAddr) -> Self { + Self::Ip(value) + } + } + + impl From for RouteDestination { + fn from(value: IpNet) -> Self { + Self::IpNet(value) + } + } + ///A `RouteTarget` describes the possible locations that traffic matching a /// route destination can be sent. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -3962,6 +4064,12 @@ pub mod types { } } + impl From for RouteTarget { + fn from(value: std::net::IpAddr) -> Self { + Self::Ip(value) + } + } + ///A route defines a rule that governs where traffic should be sent based /// on its destination. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -5643,6 +5751,12 @@ pub mod types { } } + impl From for UserPassword { + fn from(value: Password) -> Self { + Self::Password(value) + } + } + ///A single page of results #[derive(Clone, Debug, Deserialize, Serialize)] pub struct UserResultsPage { @@ -5973,6 +6087,18 @@ pub mod types { } } + impl From for VpcFirewallRuleHostFilter { + fn from(value: std::net::IpAddr) -> Self { + Self::Ip(value) + } + } + + impl From for VpcFirewallRuleHostFilter { + fn from(value: IpNet) -> Self { + Self::IpNet(value) + } + } + ///The protocols that may be specified in a firewall rule's filter #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] pub enum VpcFirewallRuleProtocol { @@ -6116,6 +6242,18 @@ pub mod types { } } + impl From for VpcFirewallRuleTarget { + fn from(value: std::net::IpAddr) -> Self { + Self::Ip(value) + } + } + + impl From for VpcFirewallRuleTarget { + fn from(value: IpNet) -> Self { + Self::IpNet(value) + } + } + ///A single rule in a VPC firewall #[derive(Clone, Debug, Deserialize, Serialize)] pub struct VpcFirewallRuleUpdate { diff --git a/progenitor-impl/tests/output/nexus-builder.out b/progenitor-impl/tests/output/nexus-builder.out index 6e0eed2..e8a393c 100644 --- a/progenitor-impl/tests/output/nexus-builder.out +++ b/progenitor-impl/tests/output/nexus-builder.out @@ -423,6 +423,54 @@ pub mod types { } } + impl From for Datum { + fn from(value: bool) -> Self { + Self::Bool(value) + } + } + + impl From for Datum { + fn from(value: i64) -> Self { + Self::I64(value) + } + } + + impl From for Datum { + fn from(value: f64) -> Self { + Self::F64(value) + } + } + + impl From> for Datum { + fn from(value: Vec) -> Self { + Self::Bytes(value) + } + } + + impl From for Datum { + fn from(value: Cumulativeint64) -> Self { + Self::CumulativeI64(value) + } + } + + impl From for Datum { + fn from(value: Cumulativedouble) -> Self { + Self::CumulativeF64(value) + } + } + + impl From for Datum { + fn from(value: Histogramint64) -> Self { + Self::HistogramI64(value) + } + } + + impl From for Datum { + fn from(value: Histogramdouble) -> Self { + Self::HistogramF64(value) + } + } + ///The type of an individual datum of a metric. #[derive( Clone, Copy, Debug, Deserialize, Eq, Hash, JsonSchema, Ord, PartialEq, PartialOrd, Serialize, @@ -2014,6 +2062,12 @@ pub mod types { } } + impl From> for InstanceNetworkInterfaceAttachment { + fn from(value: Vec) -> Self { + Self::Create(value) + } + } + ///A single page of results #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct InstanceResultsPage { @@ -2281,6 +2335,18 @@ pub mod types { } } + impl From for IpNet { + fn from(value: Ipv4Net) -> Self { + Self::V4(value) + } + } + + impl From for IpNet { + fn from(value: Ipv6Net) -> Self { + Self::V6(value) + } + } + ///Identity-related metadata that's included in nearly all public API /// objects #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] @@ -2427,6 +2493,18 @@ pub mod types { } } + impl From for IpRange { + fn from(value: Ipv4Range) -> Self { + Self::V4(value) + } + } + + impl From for IpRange { + fn from(value: Ipv6Range) -> Self { + Self::V6(value) + } + } + ///An IPv4 subnet, including prefix and subnet mask #[derive(Clone, Debug, JsonSchema, Serialize)] pub struct Ipv4Net(String); @@ -2906,6 +2984,18 @@ pub mod types { } } + impl From for NameOrId { + fn from(value: uuid::Uuid) -> Self { + Self::Id(value) + } + } + + impl From for NameOrId { + fn from(value: Name) -> Self { + Self::Name(value) + } + } + ///Supported set of sort modes for scanning by name or id #[derive( Clone, Copy, Debug, Deserialize, Eq, Hash, JsonSchema, Ord, PartialEq, PartialOrd, Serialize, @@ -3964,6 +4054,18 @@ pub mod types { } } + impl From for RouteDestination { + fn from(value: std::net::IpAddr) -> Self { + Self::Ip(value) + } + } + + impl From for RouteDestination { + fn from(value: IpNet) -> Self { + Self::IpNet(value) + } + } + ///A `RouteTarget` describes the possible locations that traffic matching a /// route destination can be sent. #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] @@ -3992,6 +4094,12 @@ pub mod types { } } + impl From for RouteTarget { + fn from(value: std::net::IpAddr) -> Self { + Self::Ip(value) + } + } + ///A route defines a rule that governs where traffic should be sent based /// on its destination. #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] @@ -5689,6 +5797,12 @@ pub mod types { } } + impl From for UserPassword { + fn from(value: Password) -> Self { + Self::Password(value) + } + } + ///A single page of results #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct UserResultsPage { @@ -6023,6 +6137,18 @@ pub mod types { } } + impl From for VpcFirewallRuleHostFilter { + fn from(value: std::net::IpAddr) -> Self { + Self::Ip(value) + } + } + + impl From for VpcFirewallRuleHostFilter { + fn from(value: IpNet) -> Self { + Self::IpNet(value) + } + } + ///The protocols that may be specified in a firewall rule's filter #[derive( Clone, Copy, Debug, Deserialize, Eq, Hash, JsonSchema, Ord, PartialEq, PartialOrd, Serialize, @@ -6170,6 +6296,18 @@ pub mod types { } } + impl From for VpcFirewallRuleTarget { + fn from(value: std::net::IpAddr) -> Self { + Self::Ip(value) + } + } + + impl From for VpcFirewallRuleTarget { + fn from(value: IpNet) -> Self { + Self::IpNet(value) + } + } + ///A single rule in a VPC firewall #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct VpcFirewallRuleUpdate { diff --git a/progenitor-impl/tests/output/nexus-positional.out b/progenitor-impl/tests/output/nexus-positional.out index f4f9762..ef587b1 100644 --- a/progenitor-impl/tests/output/nexus-positional.out +++ b/progenitor-impl/tests/output/nexus-positional.out @@ -363,6 +363,54 @@ pub mod types { } } + impl From for Datum { + fn from(value: bool) -> Self { + Self::Bool(value) + } + } + + impl From for Datum { + fn from(value: i64) -> Self { + Self::I64(value) + } + } + + impl From for Datum { + fn from(value: f64) -> Self { + Self::F64(value) + } + } + + impl From> for Datum { + fn from(value: Vec) -> Self { + Self::Bytes(value) + } + } + + impl From for Datum { + fn from(value: Cumulativeint64) -> Self { + Self::CumulativeI64(value) + } + } + + impl From for Datum { + fn from(value: Cumulativedouble) -> Self { + Self::CumulativeF64(value) + } + } + + impl From for Datum { + fn from(value: Histogramint64) -> Self { + Self::HistogramI64(value) + } + } + + impl From for Datum { + fn from(value: Histogramdouble) -> Self { + Self::HistogramF64(value) + } + } + ///The type of an individual datum of a metric. #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] pub enum DatumType { @@ -1752,6 +1800,12 @@ pub mod types { } } + impl From> for InstanceNetworkInterfaceAttachment { + fn from(value: Vec) -> Self { + Self::Create(value) + } + } + ///A single page of results #[derive(Clone, Debug, Deserialize, Serialize)] pub struct InstanceResultsPage { @@ -2003,6 +2057,18 @@ pub mod types { } } + impl From for IpNet { + fn from(value: Ipv4Net) -> Self { + Self::V4(value) + } + } + + impl From for IpNet { + fn from(value: Ipv6Net) -> Self { + Self::V6(value) + } + } + ///Identity-related metadata that's included in nearly all public API /// objects #[derive(Clone, Debug, Deserialize, Serialize)] @@ -2113,6 +2179,18 @@ pub mod types { } } + impl From for IpRange { + fn from(value: Ipv4Range) -> Self { + Self::V4(value) + } + } + + impl From for IpRange { + fn from(value: Ipv6Range) -> Self { + Self::V6(value) + } + } + ///An IPv4 subnet, including prefix and subnet mask #[derive(Clone, Debug, Serialize)] pub struct Ipv4Net(String); @@ -2568,6 +2646,18 @@ pub mod types { } } + impl From for NameOrId { + fn from(value: uuid::Uuid) -> Self { + Self::Id(value) + } + } + + impl From for NameOrId { + fn from(value: Name) -> Self { + Self::Name(value) + } + } + ///Supported set of sort modes for scanning by name or id #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] pub enum NameOrIdSortMode { @@ -3484,6 +3574,18 @@ pub mod types { } } + impl From for RouteDestination { + fn from(value: std::net::IpAddr) -> Self { + Self::Ip(value) + } + } + + impl From for RouteDestination { + fn from(value: IpNet) -> Self { + Self::IpNet(value) + } + } + ///A `RouteTarget` describes the possible locations that traffic matching a /// route destination can be sent. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -3512,6 +3614,12 @@ pub mod types { } } + impl From for RouteTarget { + fn from(value: std::net::IpAddr) -> Self { + Self::Ip(value) + } + } + ///A route defines a rule that governs where traffic should be sent based /// on its destination. #[derive(Clone, Debug, Deserialize, Serialize)] @@ -4977,6 +5085,12 @@ pub mod types { } } + impl From for UserPassword { + fn from(value: Password) -> Self { + Self::Password(value) + } + } + ///A single page of results #[derive(Clone, Debug, Deserialize, Serialize)] pub struct UserResultsPage { @@ -5265,6 +5379,18 @@ pub mod types { } } + impl From for VpcFirewallRuleHostFilter { + fn from(value: std::net::IpAddr) -> Self { + Self::Ip(value) + } + } + + impl From for VpcFirewallRuleHostFilter { + fn from(value: IpNet) -> Self { + Self::IpNet(value) + } + } + ///The protocols that may be specified in a firewall rule's filter #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] pub enum VpcFirewallRuleProtocol { @@ -5408,6 +5534,18 @@ pub mod types { } } + impl From for VpcFirewallRuleTarget { + fn from(value: std::net::IpAddr) -> Self { + Self::Ip(value) + } + } + + impl From for VpcFirewallRuleTarget { + fn from(value: IpNet) -> Self { + Self::IpNet(value) + } + } + ///A single rule in a VPC firewall #[derive(Clone, Debug, Deserialize, Serialize)] pub struct VpcFirewallRuleUpdate { diff --git a/progenitor-impl/tests/output/propolis-server-builder-tagged.out b/progenitor-impl/tests/output/propolis-server-builder-tagged.out index db0ab31..0acc1b5 100644 --- a/progenitor-impl/tests/output/propolis-server-builder-tagged.out +++ b/progenitor-impl/tests/output/propolis-server-builder-tagged.out @@ -72,6 +72,12 @@ pub mod types { } } + impl From for DiskAttachmentState { + fn from(value: uuid::Uuid) -> Self { + Self::Attached(value) + } + } + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct DiskRequest { pub device: String, @@ -575,6 +581,12 @@ pub mod types { } } + impl From for NetworkInterfaceAttachmentState { + fn from(value: Slot) -> Self { + Self::Attached(value) + } + } + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct NetworkInterfaceRequest { pub name: String, diff --git a/progenitor-impl/tests/output/propolis-server-builder.out b/progenitor-impl/tests/output/propolis-server-builder.out index 209fa85..cfc046f 100644 --- a/progenitor-impl/tests/output/propolis-server-builder.out +++ b/progenitor-impl/tests/output/propolis-server-builder.out @@ -72,6 +72,12 @@ pub mod types { } } + impl From for DiskAttachmentState { + fn from(value: uuid::Uuid) -> Self { + Self::Attached(value) + } + } + #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct DiskRequest { pub device: String, @@ -581,6 +587,12 @@ pub mod types { } } + impl From for NetworkInterfaceAttachmentState { + fn from(value: Slot) -> Self { + Self::Attached(value) + } + } + #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct NetworkInterfaceRequest { pub name: String, diff --git a/progenitor-impl/tests/output/propolis-server-positional.out b/progenitor-impl/tests/output/propolis-server-positional.out index 659b216..38c0aff 100644 --- a/progenitor-impl/tests/output/propolis-server-positional.out +++ b/progenitor-impl/tests/output/propolis-server-positional.out @@ -60,6 +60,12 @@ pub mod types { } } + impl From for DiskAttachmentState { + fn from(value: uuid::Uuid) -> Self { + Self::Attached(value) + } + } + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct DiskRequest { pub device: String, @@ -479,6 +485,12 @@ pub mod types { } } + impl From for NetworkInterfaceAttachmentState { + fn from(value: Slot) -> Self { + Self::Attached(value) + } + } + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct NetworkInterfaceRequest { pub name: String, diff --git a/progenitor/tests/build_nexus.rs b/progenitor/tests/build_nexus.rs index cfa07de..f231534 100644 --- a/progenitor/tests/build_nexus.rs +++ b/progenitor/tests/build_nexus.rs @@ -27,7 +27,22 @@ mod builder_untagged { use futures::StreamExt; mod nexus_client { - pub type MyIpv4Net = String; + use std::convert::Infallible; + + #[derive(serde::Serialize, serde::Deserialize, Debug, Clone)] + pub struct MyIpv4Net(pub String); + impl std::fmt::Display for MyIpv4Net { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(&self.0) + } + } + impl std::str::FromStr for MyIpv4Net { + type Err = Infallible; + + fn from_str(s: &str) -> Result { + Ok(Self(s.to_string())) + } + } progenitor::generate_api!( spec = "../sample_openapi/nexus.json", interface = Builder, @@ -47,7 +62,9 @@ mod builder_untagged { pub fn _ignore() { // Verify the replacement above. - let _ignore = nexus_client::types::IpNet::V4(String::new()); + let _ignore = nexus_client::types::IpNet::V4(nexus_client::MyIpv4Net( + String::new(), + )); let client = Client::new(""); let stream = client