google / serde_json5

Apache License 2.0
12 stars 9 forks source link

Match signature of `serde_*::from_reader` #4

Closed rben01 closed 3 months ago

rben01 commented 5 months ago

serde_json::from_reader has the following signature:

pub fn from_reader<R, T>(rdr: R) -> Result<T>
where
    R: Read,
    T: DeserializeOwned,

This matches the signature of serde_yaml::from_reader:

pub fn from_reader<R, T>(rdr: R) -> Result<T, Error>
where
    R: Read,
    T: DeserializeOwned,

Since this appears to be something of a de facto convention, serde_json5 should follow it. However, serde_json5::from_reader has the following signature:

pub fn from_reader<T, R>(reader: &mut R) -> Result<T>
where
    T: DeserializeOwned,
    R: Read,

This is “backwards”, and also needlessly prevents passing the reader by value (which means it has to be declared mut even if you intend for from_reader to consume it). serde_json5 should adopt the more standard signature.