Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Commit 0d062fc

Browse files
authored
Merge pull request #155 from randomguy3/documentation
Push use of derive(RustcEncodable,RustcDecodable)
2 parents 9f555b5 + 8b4ba23 commit 0d062fc

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/serialize.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,9 +805,26 @@ pub trait Decoder {
805805
/// types (like `i32` and `Vec<T>`) have `Encodable` implementations provided by
806806
/// this module.
807807
///
808+
/// Note that, in general, you should let the compiler implement this for you by
809+
/// using the `derive(RustcEncodable)` attribute.
810+
///
808811
/// # Examples
809812
///
813+
/// ```rust
814+
/// extern crate rustc_serialize;
815+
///
816+
/// #[derive(RustcEncodable)]
817+
/// struct Point {
818+
/// x: i32,
819+
/// y: i32,
820+
/// }
821+
/// # fn main() {}
810822
/// ```
823+
///
824+
/// This generates code equivalent to:
825+
///
826+
/// ```rust
827+
/// extern crate rustc_serialize;
811828
/// use rustc_serialize::Encodable;
812829
/// use rustc_serialize::Encoder;
813830
///
@@ -829,6 +846,7 @@ pub trait Decoder {
829846
/// })
830847
/// }
831848
/// }
849+
/// # fn main() {}
832850
/// ```
833851
pub trait Encodable {
834852
/// Serialize a value using an `Encoder`.
@@ -842,9 +860,26 @@ pub trait Encodable {
842860
/// types (like `i32` and `Vec<T>`) have `Decodable` implementations provided by
843861
/// this module.
844862
///
863+
/// Note that, in general, you should let the compiler implement this for you by
864+
/// using the `derive(RustcDecodable)` attribute.
865+
///
845866
/// # Examples
846867
///
868+
/// ```rust
869+
/// extern crate rustc_serialize;
870+
///
871+
/// #[derive(RustcDecodable)]
872+
/// struct Point {
873+
/// x: i32,
874+
/// y: i32,
875+
/// }
876+
/// # fn main() {}
847877
/// ```
878+
///
879+
/// This generates code equivalent to:
880+
///
881+
/// ```rust
882+
/// extern crate rustc_serialize;
848883
/// use rustc_serialize::Decodable;
849884
/// use rustc_serialize::Decoder;
850885
///
@@ -862,6 +897,7 @@ pub trait Encodable {
862897
/// })
863898
/// }
864899
/// }
900+
/// # fn main() {}
865901
/// ```
866902
pub trait Decodable: Sized {
867903
/// Deserialize a value using a `Decoder`.

0 commit comments

Comments
 (0)