ultimate-research / ssbh_lib

Reading and writing SSBH file formats in Rust
MIT License
8 stars 3 forks source link

don't duplicate export code for 8 byte aligned strings #34

Closed ScanMountGoat closed 3 years ago

ScanMountGoat commented 3 years ago

The internal string representation is an implementation detail and can just be exposed as a getter function fn text(&self) -> &str or fn text(&self) -> &str. Having separate types for 4 and 8 byte alignment should reduce the amount of repeated code for implementing SsbhWrite.

ScanMountGoat commented 3 years ago
#[cfg_attr(feature = "derive_serde", derive(Serialize, Deserialize))]
#[derive(BinRead, Debug, SsbhWrite)]
pub struct SsbhString4{
    value: RelPtr64<NullString4>
}

#[cfg_attr(feature = "derive_serde", derive(Serialize, Deserialize))]
#[derive(BinRead, Debug, SsbhWrite)]
pub struct SsbhString8{
    value: RelPtr64<NullString8>
}

#[cfg_attr(feature = "derive_serde", derive(Serialize, Deserialize))]
#[derive(BinRead, Debug, SsbhWrite)]
pub struct NullString4 {
    // NullString
}

#[cfg_attr(feature = "derive_serde", derive(Serialize, Deserialize))]
#[derive(BinRead, Debug, SsbhWrite)]
pub struct NullString8 {
    // NullString
}