How do I serialize an enum without including the name of the enum variant?

You can use the untagged attribute which will produce the desired output. You won’t need to implement Serialize yourself with this: #[derive(Debug, Serialize)] #[serde(untagged)] enum TValue<‘a> { String(&’a str), Int(&’a i32), } If you wanted to implement Serialize yourself, I believe you want to skip your variant so you should not use serialize_newtype_variant() as it … Read more

What’s the difference between using the return statement and omitting the semicolon in Rust?

A return statement, otherwise known as an early return, will return an object from the last/innermost function-like scope. (Function-like because it applies to both closures and functions) let x = || { return 0; println!(“This will never happen!”); }; fn foo() { return 0; println!(“This won’t happen either”); } An absent semicolon will instead evaluate … Read more