Recommended layout for serde for type with two formats

I've written a serialization/deserialization library for Linden Lab Serial Data. It's not Serde-compatible, and I want to make it work with Serde.

There are two output forms - XML, and "binary". Should this be two crates, or one? If one, how should this be organized?

I have written a format which supports both binary and text representations in the same crate. You can take a look for inspiration. My personal experience is that it's a lot easier to do if you stay within the same crate (because common code won't have to be pulled out to a 3rd, separate crate), and your users will probably be happier, too, because they won't have to memorize two crate names.

Thanks.

Links from https://crates.io/crates/neodyn_xc to the repository are dead links. Moved?

Oh, sorry, not exactly – the format is in a common repo with other (research) stuff which is private. You can find the source on docs.rs instead.

OK, followed that general format. Code at GitHub - John-Nagle/serde-llsd: Serialization library for Linden Lab Serial Data format. Rust Serde version.

Not quite clear on the best way to expose the public function calls. Using the suggested form produces a name clash, because this promotes all those calls to the top level of the crate. What's the best convention on this?

pub use crate::{
    de::{
        binary::from_bytes,
        ////binary::from_reader,    // Name clash
        xml::from_reader,
        xml::from_str,
    },
    ser::{
        binary::to_bytes,
        ////binary::to_writer,  // Name clash
        xml::to_string,
        xml::to_writer,
    },
};
pub use crate::{
    de::{
        binary::from_bytes,
        binary::from_reader as from_reader_to_binary, 
        xml::from_reader as from_reader_to_xml,
        xml::from_str,
    },
    ser::{
        binary::to_bytes,
        binary::to_writer as to_binary_writer,
        xml::to_string,
        xml::to_writer as to_xml_writer,
    },
};

Not clear about the naming convention here, but if you need another naming, as is what you want.

a simple as example linked to playground

The naming convention is the whole point. Serde is mostly a naming convention, after all.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.