Mention that TryFrom can be used just as FromStr.

This commit is contained in:
Jimmy Cuadra 2019-07-23 01:00:47 -07:00
parent abac13a7dd
commit 41ef94a617

View File

@ -74,13 +74,17 @@
//!
//! All concrete event types in ruma-events can be serialized via the `Serialize` trait from
//! [serde](https://serde.rs/) and can be deserialized from a `&str` of JSON data via the `FromStr`
//! trait from the standard library. In order to handle incoming data that may not conform to
//! trait from the standard library. (`TryFrom<&str>` is also implemented and can be used in place
//! of `FromStr` if preferred.) In order to handle incoming data that may not conform to
//! ruma-events's strict definitions of event structures, deserializing from JSON will return an
//! `InvalidEvent` on error. This error covers both invalid JSON data as well as valid JSON that
//! doesn't match the structure expected by ruma-events's event types. In the latter case, the
//! error exposes the deserialized `serde_json::Value` so that developers can still work with the
//! received event data. This also makes it possible to deserialize a collection of events without
//! the entire collection failing to deserialize due to a single invalid event.
//! doesn't match the structure expected by ruma-events's event types. In the latter case, the error
//! exposes the deserialized `serde_json::Value` so that developers can still work with the received
//! event data. This also makes it possible to deserialize a collection of events without the entire
//! collection failing to deserialize due to a single invalid event. The "content" type for each
//! event also implements `Serialize` and either `FromStr` (for dedicated content types) or
//! `Deserialize` (when the content is a type alias), allowing content to be converted to and from
//! JSON indepedently of the surrounding event structure, if needed.
//!
//! # Collections
//!