File: queue.rs

package info (click to toggle)
rust-openssh-sftp-client-lowlevel 0.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 196 kB
  • sloc: sh: 4; makefile: 2
file content (27 lines) | stat: -rw-r--r-- 594 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use std::{mem, sync::Mutex};

use bytes::Bytes;
use openssh_sftp_client_lowlevel::Queue;

#[derive(Default)]
pub struct MpscQueue(Mutex<Vec<Bytes>>);

impl MpscQueue {
    pub fn consume(&self) -> Vec<Bytes> {
        mem::take(&mut *self.0.lock().unwrap())
    }
}

impl Queue for MpscQueue {
    fn push(&self, bytes: Bytes) {
        self.0.lock().unwrap().push(bytes);
    }

    fn extend(&self, header: Bytes, body: &[&[Bytes]]) {
        let mut v = self.0.lock().unwrap();
        v.push(header);
        for data in body {
            v.extend(data.iter().cloned());
        }
    }
}