Skip to content

Commit

Permalink
Add test of generic remote derive with getter
Browse files Browse the repository at this point in the history
Currently fails to compile.

    error[E0107]: missing generics for struct `StructGeneric`
       --> test_suite/tests/test_remote.rs:181:18
        |
    181 | #[serde(remote = "remote::StructGeneric")]
        |                  ^^^^^^^^^^^^^^^^^^^^^^^ expected 1 generic argument
        |
    note: struct defined here, with 1 generic parameter: `T`
       --> test_suite/tests/test_remote.rs:78:16
        |
    78  |     pub struct StructGeneric<T> {
        |                ^^^^^^^^^^^^^ -
    help: add missing generic argument
        |
    181 | #[serde(remote = StructGeneric<T>)]
        |                  ~~~~~~~~~~~~~~~~
  • Loading branch information
dtolnay committed Nov 28, 2022
1 parent fabbd2b commit 7328b34
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test_suite/tests/test_remote.rs
Expand Up @@ -79,6 +79,12 @@ mod remote {
pub value: T,
}

impl<T> StructGeneric<T> {
pub fn get_value(&self) -> &T {
&self.value
}
}

pub enum EnumGeneric<T> {
Variant(T),
}
Expand Down Expand Up @@ -171,6 +177,13 @@ struct StructPubDef {
b: remote::Unit,
}

#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::StructGeneric")]
struct StructGenericWithGetterDef<T> {
#[serde(getter = "remote::StructGeneric::get_value")]
value: T,
}

#[derive(Serialize, Deserialize)]
#[serde(remote = "remote::StructGeneric<u8>")]
struct StructConcrete {
Expand Down Expand Up @@ -206,3 +219,9 @@ impl From<StructPrivDef> for remote::StructPriv {
remote::StructPriv::new(def.a, def.b)
}
}

impl<T> From<StructGenericWithGetterDef<T>> for remote::StructGeneric<T> {
fn from(def: StructGenericWithGetterDef<T>) -> Self {
remote::StructGeneric { value: def.value }
}
}

0 comments on commit 7328b34

Please sign in to comment.