Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 19, 2020. It is now read-only.

Add explanation of the format module.#56

Open
teymour-aldridge wants to merge 4 commits into
yewstack:master from
teymour-aldridge:explain-format-module
Open

Add explanation of the format module. #56
teymour-aldridge wants to merge 4 commits into
yewstack:master from
teymour-aldridge:explain-format-module

Conversation

@teymour-aldridge

@teymour-aldridge teymour-aldridge commented Apr 16, 2020

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread src/concepts/services/format.md Outdated
Comment on lines +10 to +13
// convert the data into JSON
let json_data = Json(&data);
// convert the JSON back
let Json(dump) = json_data;

Copy link
Copy Markdown
Member

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

@jstarry jstarry May 3, 2020

Copy link
Copy Markdown
Member

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

Comment thread 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).

Copy link
Copy Markdown
Member

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

Comment thread src/concepts/services/format.md Outdated
```

## Further reading
* [The API documentation](https://docs.rs/yew/0.14.3/yew/format/index.html)

Copy link
Copy Markdown
Member

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 {

@jstarry jstarry May 3, 2020

Copy link
Copy Markdown
Member

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()));

@jstarry jstarry May 3, 2020

Copy link
Copy Markdown
Member

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

1 more reviewer

@jstarry jstarry jstarry left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /