specta-rs / specta

Easily export your Rust types to other languages
MIT License
273 stars 38 forks source link

Implementing specta::Type for types from other crates? #286

Closed amosjyng closed 1 day ago

amosjyng commented 2 days ago

I can't do this

use asciicast::{Entry, Header};

#[derive(specta::Type)]
pub struct AsciiCastData {
    pub header: Header,
    pub entries: Vec<Entry>,
}

because

the trait bound `Header: specta::Type` is not satisfied

But neither can I manually implement it

use specta::datatype::{DataType, StructType};

impl specta::Type for AsciiCastData {
    fn inline(type_map: &mut specta::TypeMap, generics: specta::Generics) -> DataType {
        DataType::Struct(
            StructType {
                name: "AsciiCastData".to_string(),
                sid: None,
                fields: vec![
                    ...
                ],
                generics: vec![],
            }
        )
    }
}

because those fields are private to the crate.

Do you have any recommendations?

sleepyfran commented 2 days ago

fyi: this was discussed in #284. Also, see this for a more detailed answer.

amosjyng commented 1 day ago

Oh nice! Somehow I didn't find those issues when I did a search. Thanks!