Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example, fix deprecated warning, update Cargo.toml #93

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[package]
name = "serde_urlencoded"
version = "0.7.1" # bump in documentation link and in README on update
version = "0.7.1" # bump in README on update
authors = ["Anthony Ramine <[email protected]>"]
license = "MIT/Apache-2.0"
repository = "https://github.com/nox/serde_urlencoded"
documentation = "https://docs.rs/serde_urlencoded/0.7.1/serde_urlencoded/"
documentation = "https://docs.rs/serde_urlencoded/"
readme = "README.md"
description = "`x-www-form-urlencoded` meets Serde"
categories = ["encoding", "web-programming"]
keywords = ["serde", "serialization", "urlencoded"]
Expand Down
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,37 @@ serde_urlencoded = "0.7"
The documentation is available on [docs.rs].

[crates.io]: https://crates.io/crates/serde_urlencoded
[docs.rs]: https://docs.rs/serde_urlencoded/0.7.1/serde_urlencoded/
[docs.rs]: https://docs.rs/serde_urlencoded

## Example

This example assumes you also have `serde = { version = "1", features = ["derive"] }` in your `Cargo.toml`:

```rust
use serde_urlencoded::{from_str, to_string};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
struct QueryParameters {
page: u32,
name: String,
}

fn main() {
let params = QueryParameters {
page: 42,
name: "The name of the album".into(),
};

let actual_encoded = to_string(params.clone()).expect("Should serialize");
let expected_encoded = "page=42&name=The+name+of+the+album";

assert_eq!(expected_encoded, actual_encoded);

let expected = from_str::<QueryParameters>(expected_encoded).expect("Should deserialize");
assert_eq!(expected, params);
}
```

## Getting help

Expand Down
23 changes: 23 additions & 0 deletions examples/use.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use serde_urlencoded::{from_str, to_string};
use serde_derive::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
struct QueryParameters {
page: u32,
name: String,
}

fn main() {
let params = QueryParameters {
page: 42,
name: "The name of the album".into(),
};

let actual_encoded = to_string(params.clone()).expect("Should serialize");
let expected_encoded = "page=42&name=The+name+of+the+album";

assert_eq!(expected_encoded, actual_encoded);

let expected = from_str::<QueryParameters>(expected_encoded).expect("Should deserialize");
assert_eq!(expected, params);
}
7 changes: 0 additions & 7 deletions src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ impl fmt::Display for Error {
}

impl error::Error for Error {
fn description(&self) -> &str {
match *self {
Error::Custom(ref msg) => msg,
Error::Utf8(ref err) => error::Error::description(err),
}
}

/// The lower-level cause of this error, in the case of a `Utf8` error.
fn cause(&self) -> Option<&dyn error::Error> {
match *self {
Expand Down