-
Hi! Was just wondering if anyone knows a way to handle To avoid the x y problem; what I'm really trying to do, is represent Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I guess I could achieve what I'm trying to do by joining the |
Beta Was this translation helpful? Give feedback.
-
I found this to be a little simpler: #[derive(Debug, PartialEq, DekuRead, DekuWrite)]
pub struct DekuString {
#[deku(bytes = "1")]
content_len: u8,
#[deku(count = "content_len")]
content: Vec<u8>,
}
impl Into<String> for DekuString {
fn into(self) -> String {
String::from_utf8_lossy(&self.content).to_string()
}
}
impl From<String> for DekuString {
fn from(value: String) -> Self {
// TODO: Handle u8 conversion
DekuString { content_len: value.len() as u8, content: Vec::from(value) }
}
} and then doing: #[derive(Debug, PartialEq, DekuRead, DekuWrite)]
pub struct Foo {
#[deku(bytes = "1")]
foo_len: u8,
#[deku(count = "foo_len")]
foo: Vec<DekuString>,
} Please let me know if there are better ways 🙇 |
Beta Was this translation helpful? Give feedback.
I found this to be a little simpler:
and then doing: