rsocket / rsocket-rust

RSocket Rust Implementation using Tokio
Apache License 2.0
209 stars 19 forks source link

Convert Result to Option when use std::str::from_utf8 #26

Closed linux-china closed 3 years ago

linux-china commented 3 years ago

代码中有不少地方涉及到Result转换为Option, 使用expect会导致panic错误,这种场景中,可能转换为None可能更符合语义,如std::str::from_utf8(b.as_ref()).ok()

pub fn data_utf8(&self) -> Option<&str> {
        match &self.d {
            Some(b) => Some(std::str::from_utf8(b.as_ref()).expect("Invalid UTF-8 bytes.")),
            None => None,
        }
    }
jjeffcaii commented 3 years ago

👍 收到~