GithubHelp home page GithubHelp logo

Comments (4)

alt-art avatar alt-art commented on September 4, 2024

I don't use enums because I have no experience with them, the examples of the enum representation of serde seems disheartening, if you have an example of this I will check.

Genius API supports many types of searches, but they only offer developers a small music search, in a no longer future I will support these types.

from genius-rs.

vrobweis avatar vrobweis commented on September 4, 2024

Without confirming (I am away from a computer at present), a possible representation could look like:

#[derive(Deserialize, Debug)] 
#[serde(tag = "type", content = "result")]
#[non_exhaustive]
pub enum Hit {
    #[serde(alias = "song")]
    Song(Song)
}

This uses serde's support for adjacent tagging to handle possible outcomes. This sample code may not be ideal, as it does remove support for the index value, but by my recollection, that information isn't really something consumers of the crate would use, since they would presumably get whatever results they need in the Vec of Hits. If the index is used for pagination, that's a crate implementation detail.

from genius-rs.

alt-art avatar alt-art commented on September 4, 2024

Hmm, the way you did it would be possible:

#[derive(Deserialize, Debug)] 
#[serde(tag = "type", content = "result")]
#[serde(tag = "type", content = "album")]
#[non_exhaustive]
pub enum Hit {
    #[serde(alias = "song")]
    Song(Song)
    #[serde(alias = "album")]
    Album(Album)
}

?

from genius-rs.

alt-art avatar alt-art commented on September 4, 2024

I reviewed the API responses for certain types of search and I think that even, so I will have to write another structure to treat some cases.
See multiple types search, articles search and tiny song search.
The tiny music search will be separated from the others responses.

from genius-rs.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.