如题,演示Rust 标记一个属性或函数为废弃的基本使用方法:
示例:
use serde::{Deserialize, Serialize};#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct GrpcOptions {pub addr: String,pub max_recv_message_size: u32,pub max_send_message_size: u32,pub hostname: String,
}#[derive(Clone, Debug, Serialize, Deserialize, Default)]
#[serde(default)]
pub struct DatanodeOptions {pub node_id: Option<u64>,pub require_lease_before_startup: bool,pub init_regions_in_background: bool,#[deprecated(note = "use `grpc.hostname` instead")]pub rpc_hostname: Option<String>,pub grpc: GrpcOptions,
}fn main() {let mut datanode = DatanodeOptions::default();datanode.grpc.hostname = "hostname".to_string();datanode.rpc_hostname = Some("dep_hostname".to_string());println!("{:?}", datanode);
}
最后输出如下所示: