-
Notifications
You must be signed in to change notification settings - Fork 46
Add explanation of the format module. #56
base: master
Are you sure you want to change the base?
Add explanation of the format module. #56
Conversation
src/concepts/services/format.md
Outdated
// convert the data into JSON | ||
let json_data = Json(&data); | ||
// convert the JSON back | ||
let Json(dump) = json_data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this example isn't actually doing any conversion. Could you change it to match what you have below with Into
/From
Text or Binary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@teymour-aldridge I don't think you addressed this comment
src/concepts/services/format.md
Outdated
`Contribute to our docs:` [Explain the format module in depth](https://github.com/yewstack/docs/issues/24) | ||
{% endhint %} | ||
## Introduction | ||
Yew provides the format module to make it easy to convert from Rust types to common data formats (and vice versa). Rust provides support for a number of different data formats. Some of these formats are binary-only (e.g. CBOR) while others support both text and binary (e.g. JSON). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also like if there was a usage section. The format module is not a service itself, but is necessary for using the FetchService
and WebSocketService
src/concepts/services/format.md
Outdated
``` | ||
|
||
## Further reading | ||
* [The API documentation](https://docs.rs/yew/0.14.3/yew/format/index.html) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: drop the version from the url so it always goes to latest
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct APIRequest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think this naming is confusing. Maybe you could name it like RequestData
?
// convert the custom data type into JSON text – note that `.into()` had to be called before the data was converted | ||
let raw_api_request: Text = Json(&new_request).into(); | ||
// convert the JSON back into our custom data type. | ||
let Json(rebuilt_request): Json<Result<APIRequest, _>> = Json::from(Ok(raw_api_request.unwrap())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you unwrap
and then re-wrap with Ok
?
No description provided.