servo / servo/rust-url

Host Serialize and Deserialize instances not so useful?

Open
#543 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.6k
Forks
406
PR merge metrics
No merged PRs in 30d

Description

From looking at the code it seems that the serde Serialize and Desirialize instances for Host are automatically derived, meaning that the resulting behaviour is perhaps less useful, as the enum is tagged with its name, for example

#[derive(Serialize)]
struct MyStruct {
    host: Host 
}

fn main() {
    let foo = MyStruct {
        host: Host::parse("www.google.com").unwrap()
    };
    println!("{}", serde_json::to_string(&foo).unwrap());
}

Produces

{"host":{"Domain":"www.google.com"}}

I feel that having these instances spit out the host in question without the enum tag would probably be more intuitive and useful to end users as right now things are coupled to the implementation details of Host, what do people think?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the Host serde Serialize and Deserialize implementations or derives, then reproduce the issue's serde_json example. The proposed representation is not decided in the discussion, so first get maintainer agreement on the wire format; done means the agreed behavior is implemented and covered by serialization tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
json, rust
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.