replace unwrap with expect

This commit is contained in:
2024-12-29 02:11:14 +01:00
parent aec488a74e
commit f014e6f082
+3 -5
View File
@@ -22,7 +22,7 @@ fn encode<'a>(encode_buf: &mut String, writer: &'a mut EmailWriter) {
} }
let prefix = encode_buf.trim_end_matches(' '); let prefix = encode_buf.trim_end_matches(' ');
email_encoding::headers::rfc2047::encode(prefix, writer).expect("we can always write to a string"); email_encoding::headers::rfc2047::encode(prefix, writer).expect("String is always writable");
// TODO: add a better API for doing this in email-encoding // TODO: add a better API for doing this in email-encoding
let spaces = encode_buf.len() - prefix.len(); let spaces = encode_buf.len() - prefix.len();
@@ -39,15 +39,13 @@ fn encode_header_value(key: &str, value: &str) -> String {
let mut writer = EmailWriter::new(&mut encoded_value, line_len, 0, false); let mut writer = EmailWriter::new(&mut encoded_value, line_len, 0, false);
let mut encode_buf = String::new(); let mut encode_buf = String::new();
for next_word in value.split_inclusive(' ') { for next_word in value.split_inclusive(' ') {
let allowed = allowed_str(next_word); if allowed_str(next_word) {
if allowed {
// This word only contains allowed characters // This word only contains allowed characters
// the next word is allowed, but we may have accumulated some words to encode // the next word is allowed, but we may have accumulated some words to encode
encode(&mut encode_buf, &mut writer); encode(&mut encode_buf, &mut writer);
writer.folding().write_str(next_word).expect("we can always write to a string"); writer.folding().write_str(next_word).expect("String is always writable");
} else { } else {
// This word contains unallowed characters // This word contains unallowed characters
encode_buf.push_str(next_word); encode_buf.push_str(next_word);