diff --git a/codegen/src/lib.rs b/codegen/src/lib.rs index e5b0ccc..afe30f3 100644 --- a/codegen/src/lib.rs +++ b/codegen/src/lib.rs @@ -50,7 +50,11 @@ fn typename_s(ty: &str) -> String { } fn type_attrs(ty: &spec::Type) -> String { - feature_attrs(&ty.features) + if ty.features.is_deprecated() { + " #[cfg(feature = \"deprecated\")] #[deprecated]".into() + } else { + String::new() + } } fn feature_attrs(ty: &spec::Features) -> String { @@ -353,6 +357,10 @@ pub struct {} {{ let field_ty = typename(&field.ty); let field_name = identifier(&field.name); let into = if field.optional { ".into()" } else { "" }; + let deprecated_primary = field.ty.features.is_deprecated(); + if deprecated_primary { + write!(self.out, "\n#[cfg(feature = \"deprecated\")]")?; + } write!(self.out, " impl> From for {} {{ fn from(val: T) -> Self {{ @@ -361,7 +369,8 @@ impl> From for {} {{ ", field_ty, struct_id, field_name, into)?; if newtype.is_none() { for field in &v.data.fields { - writeln!(self.out, "{}: Default::default(),", identifier(&field.name))?; + let cfg = if field.ty.features.is_deprecated() { "#[cfg(feature = \"deprecated\")] " } else { "" }; + writeln!(self.out, "{}{}: Default::default(),", cfg, identifier(&field.name))?; } } write!(self.out, " @@ -369,6 +378,9 @@ impl> From for {} {{ }} }}")?; if !field.optional { + if deprecated_primary { + write!(self.out, "\n#[cfg(feature = \"deprecated\")]")?; + } write!(self.out, " impl AsRef<{}> for {} {{ fn as_ref(&self) -> &{} {{ @@ -380,6 +392,10 @@ impl> From for {} {{ if let Some(field) = wrapper { let field_ty = typename(&field.ty); let field_name = identifier(&field.name); + let deprecated_wrapper = field.ty.features.is_deprecated(); + if deprecated_wrapper { + write!(self.out, "\n#[cfg(feature = \"deprecated\")]")?; + } write!(self.out, " impl ::std::ops::Deref for {} {{ type Target = {}; @@ -388,6 +404,9 @@ impl ::std::ops::Deref for {} {{ &self.{} }} }}", struct_id, field_ty, field_name)?; + if deprecated_wrapper { + write!(self.out, "\n#[cfg(feature = \"deprecated\")]")?; + } write!(self.out, " impl {} {{ pub fn into_inner(self) -> {} {{ diff --git a/qapi/Cargo.toml b/qapi/Cargo.toml index e349b83..1b50cf0 100644 --- a/qapi/Cargo.toml +++ b/qapi/Cargo.toml @@ -44,3 +44,4 @@ async-tokio-net = ["async-tokio", "tokio/net"] async-tokio-spawn = ["async-tokio", "tokio/rt"] async-tokio-all = ["async-tokio-net", "async-tokio-spawn"] async-tower = ["async", "tower-service"] +deprecated = ["qapi-qmp?/deprecated", "qapi-qga?/deprecated"] diff --git a/qga/Cargo.toml b/qga/Cargo.toml index 22f14bb..30b7109 100644 --- a/qga/Cargo.toml +++ b/qga/Cargo.toml @@ -20,6 +20,9 @@ maintenance = { status = "passively-maintained" } [build-dependencies] qapi-codegen = { version = "^0.10.2", path = "../codegen" } +[features] +deprecated = [] + [dependencies] serde = { version = "^1.0.27", features = [ "derive" ] } qapi-spec = { version = "^0.3.0", path = "../spec" } diff --git a/qmp/Cargo.toml b/qmp/Cargo.toml index 0860980..b69bdb5 100644 --- a/qmp/Cargo.toml +++ b/qmp/Cargo.toml @@ -20,6 +20,9 @@ maintenance = { status = "passively-maintained" } [build-dependencies] qapi-codegen = { version = "^0.10.2", path = "../codegen" } +[features] +deprecated = [] + [dependencies] serde = { version = "^1.0.27", features = [ "derive" ] } qapi-spec = { version = "^0.3.0", path = "../spec" }