We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d24c527 commit 03251aeCopy full SHA for 03251ae
crates/league-modpkg/src/utils.rs
@@ -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
- }
+pub fn optional_string_len<'a>(string: impl Into<Option<&'a String>>) -> usize {
+ string.into().as_ref().map(|n| n.len()).unwrap_or_default()
6
}
7
8
-pub fn length_prefixed_string_size(value: impl AsRef<str>) -> usize {
9
- value.as_ref().len() + 4
+pub fn optional_string_write(s: &Option<String>) -> Option<Vec<u8>> {
+ s.as_ref().map(|s| s.as_bytes().to_vec())
+}
+pub fn optional_string_read(s: Vec<u8>) -> Result<Option<String>, std::string::FromUtf8Error> {
+ String::from_utf8(s).map(Some)
10
0 commit comments