mirror of
https://github.com/n0-computer/noq.git
synced 2026-10-13 16:22:11 +00:00
Clean up a few Option/Result patterns that fit an std combinator
(cherry picked from commit f731019c83)
This commit is contained in:
committed by
Dirkjan Ochtman
parent
50aa79af9b
commit
add7e4cca5
@@ -51,10 +51,7 @@ impl Assembler {
|
||||
/// Get the the next chunk
|
||||
pub(crate) fn read(&mut self, max_length: usize, ordered: bool) -> Option<Chunk> {
|
||||
loop {
|
||||
let mut chunk = match self.data.peek_mut() {
|
||||
Some(chunk) => chunk,
|
||||
None => return None,
|
||||
};
|
||||
let mut chunk = self.data.peek_mut()?;
|
||||
|
||||
if ordered {
|
||||
if chunk.offset > self.bytes_read {
|
||||
|
||||
@@ -254,10 +254,11 @@ impl<'a> SendStream<'a> {
|
||||
/// # Panics
|
||||
/// - when applied to a receive stream
|
||||
pub fn reset(&mut self, error_code: VarInt) -> Result<(), UnknownStream> {
|
||||
let stream = match self.state.send.get_mut(&self.id) {
|
||||
Some(ss) => ss,
|
||||
None => return Err(UnknownStream { _private: () }),
|
||||
};
|
||||
let stream = self
|
||||
.state
|
||||
.send
|
||||
.get_mut(&self.id)
|
||||
.ok_or(UnknownStream { _private: () })?;
|
||||
|
||||
if matches!(stream.state, SendState::ResetSent) {
|
||||
// Redundant reset call
|
||||
@@ -280,10 +281,11 @@ impl<'a> SendStream<'a> {
|
||||
/// # Panics
|
||||
/// - when applied to a receive stream
|
||||
pub fn set_priority(&mut self, priority: i32) -> Result<(), UnknownStream> {
|
||||
let stream = match self.state.send.get_mut(&self.id) {
|
||||
Some(ss) => ss,
|
||||
None => return Err(UnknownStream { _private: () }),
|
||||
};
|
||||
let stream = self
|
||||
.state
|
||||
.send
|
||||
.get_mut(&self.id)
|
||||
.ok_or(UnknownStream { _private: () })?;
|
||||
|
||||
stream.priority = priority;
|
||||
Ok(())
|
||||
@@ -294,10 +296,11 @@ impl<'a> SendStream<'a> {
|
||||
/// # Panics
|
||||
/// - when applied to a receive stream
|
||||
pub fn priority(&self) -> Result<i32, UnknownStream> {
|
||||
let stream = match self.state.send.get(&self.id) {
|
||||
Some(ss) => ss,
|
||||
None => return Err(UnknownStream { _private: () }),
|
||||
};
|
||||
let stream = self
|
||||
.state
|
||||
.send
|
||||
.get(&self.id)
|
||||
.ok_or(UnknownStream { _private: () })?;
|
||||
|
||||
Ok(stream.priority)
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ fn process_get(root: &Path, x: &[u8]) -> Result<Vec<u8>> {
|
||||
bail!("missing \\r\\n");
|
||||
}
|
||||
let x = &x[4..x.len() - 2];
|
||||
let end = x.iter().position(|&c| c == b' ').unwrap_or_else(|| x.len());
|
||||
let end = x.iter().position(|&c| c == b' ').unwrap_or(x.len());
|
||||
let path = str::from_utf8(&x[..end]).context("path is malformed UTF-8")?;
|
||||
let path = Path::new(&path);
|
||||
let mut real_path = PathBuf::from(root);
|
||||
|
||||
Reference in New Issue
Block a user