介绍
- 主页 Homepage
- 基础库 https://crates.io/crates/lwleen-rpc
- 应用库 https://crates.io/crates/lwleen
- crates文档 https://docs.rs/lwleen-macro
⚡️ 快速开始
rust孤儿规则
当为类型 T 实现特征 Trait 时,T 或 Trait 必须至少有一个是在当前 crate 中定义的。
use lwleen_macro::gen_特征_derive;
// 为 impl代码块 实现特征声明
#[gen_特征_derive(特征名A)]
impl 信令路由{
fn abc(&self,参数a:String,参数b:u64)->anyhow_Result<()>{
}
}
// 代码展开后 ->
pub trait 特征名A {
fn abc(&self,参数a:String,参数b:u64)->anyhow_Result<()>;
}
impl 特征名A for 信令路由{
fn abc(&self,参数a:String,参数b:u64)->anyhow_Result<()>{
}
}
struct Appdata<T>{ a:String, b:T }
#[gen_特征_derive(特征A<T>)]
impl<T> 特征A<T> for Appdata<T> where T:Into<u64>{
fn out(self){ println!("{:?} {}",self.a , self.b.into() + 5 ); }
}
// 代码展开后 ->
pub trait 特征名A<T> {
fn out(self);
}
impl <T> 特征A<T> for Appdata<T> where T:Into<u64>{
fn out(self){ println!("{:?} {}",self.a , self.b.into() + 5 ); }
}
//---- 测试 stdout ----
let a = Appdata{ a:"test".to_string() , b: 100u64 };
a.out();
//输出: "test" 105
EnumDisplay
#[derive(EnumDisplay)]
pub enum 枚举类型{
分支A,
分支B,
}
println!("{}", 枚举类型::分支A.to_string() );
//输出: 分支A