Shing Lyu's Random Tech Facts

This is a micro-blog where I write one-liners about random tech stuff I learned.

How to import serde's custom derive macors properly?

TL;DR Follow the official documentation

A little bit of history:

extern crate serde;
#[macro_use] extern crate serde_derive; // Imports the procedural macros

#[derive(Serialize, Deserialize)]
struct Foo;
use serde_derive::{Serialize, Deserialize}; // Imports the procedural macros

#[derive(Serialize, Deserialize)]
struct Foo;
// Cargo.toml
[dependencies]
serde = { version = "1.0", features = ["derive"] }

// src/main.rs or lib.rs
use serde::{Serialize, Deserialize}; // Imports both the traits and procedural macros

#[derive(Serialize, Deserialize)]
struct Foo;