Skip to content

Commit 03251ae

Browse files
committed
feat: add binrw utils
1 parent d24c527 commit 03251ae

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

crates/league-modpkg/src/utils.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
pub fn non_empty_string(value: String) -> Option<String> {
2-
match value.is_empty() {
3-
true => None,
4-
false => Some(value),
5-
}
1+
pub fn optional_string_len<'a>(string: impl Into<Option<&'a String>>) -> usize {
2+
string.into().as_ref().map(|n| n.len()).unwrap_or_default()
63
}
74

8-
pub fn length_prefixed_string_size(value: impl AsRef<str>) -> usize {
9-
value.as_ref().len() + 4
5+
pub fn optional_string_write(s: &Option<String>) -> Option<Vec<u8>> {
6+
s.as_ref().map(|s| s.as_bytes().to_vec())
7+
}
8+
pub fn optional_string_read(s: Vec<u8>) -> Result<Option<String>, std::string::FromUtf8Error> {
9+
String::from_utf8(s).map(Some)
1010
}

0 commit comments

Comments
 (0)