1、第三届中国Rust开发者大会Candid:the interface description language of the Internet Computer smart contractsYan ChenDFINITY FoundationRust China Conf 2023 How DFINITY uses procedure macro to extend RustOverviewOverview Macro system is a hidden gem in Rust.We share our experience in safely extending Rust languag
2、es without modifying the compiler.Running example:Candid,a strongly typed serialization library Extended language features:Backward compatible API upgrades with subtyping Type reflection Structural typingMotivationMotivation How to maintain interoperability between microservices?MotivationMotivation
3、 How to maintain interoperability between microservices?UpgradeMotivationMotivation How to maintain interoperability between microservices?APIs are allowed to evolve without breaking existing client Wire format contains type information Decoder knows two types:wire type,and expected typeServing API
4、v2Client only knows API v1Send v1 dataDecode v1 as v2Send v2 resultDecode v2 as v1MotivationMotivation How to maintain interoperability between microservices?APIs are allowed to evolve without breaking existing client Wire format contains type information Decoder knows two types:wire type,and expect
5、ed typeServing API v2Client only knows API v1Send v1 dataDecode v1 as v2Send v2 resultDecode v2 as v1ContravarianceCovarianceSubtyping and safe upgradesSubtyping and safe upgrades Outbound data(provided by service)can upgrade to more specific data Inbound data(required by service)can upgrade to more
6、 general data Orientation is inverted for higher order functionsv3v2v1v1v2v3f :Send(record age=42:nat8)Send(record name=”Admin”;age=42:nat8)ExampleExampletype Profile=record name:text;service:getProfile:(nat)-(Profile);API v1type Profile=record name:text;age:nat8;service:getProfile:(nat)-(Profile);A