serde-feature-hack

Crates.ioserde-feature-hack
lib.rsserde-feature-hack
version0.2.1
sourcesrc
created_at2018-08-26 19:43:55.231048
updated_at2022-01-27 13:21:14.704758
descriptionA hack to allow having a feature named serde while having serde as a dependency
homepage
repositoryhttps://gitlab.com/KonradBorowski/serde-feature-hack
max_upload_size
id81548
size5,508
Kamila Borowska (xfix)

documentation

README

serde-feature-hack

DEPRECATED: Since Rust 1.31 it's possible to rename dependencies. There is no need to use this crate anymore.

A hack to allow having a feature named serde which doesn't just depend on serde

In Cargo.toml, you can do the following:

[dependencies]
serde-feature-hack = { version = "0.1.0", optional = true }

[features]
serde = ["serde-feature-hack", "some-other-dependency"]

Then, you can use serde like you normally would, except the crate name is serde_feature_hack. It's possible to import it with the usual serde name.

extern crate serde_feature_hack as serde;
extern crate serde_json;

use serde::{Serialize, Serializer};

struct X;

impl Serialize for X {
    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.serialize_str("Hello, world!")
    }
}

assert_eq!(serde_json::to_string(&X).unwrap(), r#""Hello, world!""#);
Commit count: 8

cargo fmt