Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<T: Into<{}>> From<T> for {} {{
fn from(val: T) -> Self {{
Expand All @@ -361,14 +369,18 @@ impl<T: Into<{}>> From<T> 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, "
}}
}}
}}")?;
if !field.optional {
if deprecated_primary {
write!(self.out, "\n#[cfg(feature = \"deprecated\")]")?;
}
write!(self.out, "
impl AsRef<{}> for {} {{
fn as_ref(&self) -> &{} {{
Expand All @@ -380,6 +392,10 @@ impl<T: Into<{}>> From<T> 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 = {};
Expand All @@ -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) -> {} {{
Expand Down
1 change: 1 addition & 0 deletions qapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
3 changes: 3 additions & 0 deletions qga/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
3 changes: 3 additions & 0 deletions qmp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Loading