base/sys/unix/
iobuf.rs

1// Copyright 2020 The ChromiumOS Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use std::ffi::c_void;
6
7use libc::iovec;
8
9use crate::iobuf::PlatformIoBuf;
10
11/// Cross platform binary compatible iovec. See [`crate::IoBufMut`] for documentation.
12pub type IoBuf = iovec;
13
14impl PlatformIoBuf for IoBuf {
15    #[inline]
16    fn new(ptr: *mut u8, len: usize) -> Self {
17        iovec {
18            iov_base: ptr as *mut c_void,
19            iov_len: len,
20        }
21    }
22
23    #[inline]
24    fn len(&self) -> usize {
25        self.iov_len
26    }
27
28    #[inline]
29    fn ptr(&self) -> *mut u8 {
30        self.iov_base as *mut u8
31    }
32
33    #[inline]
34    fn set_len(&mut self, len: usize) {
35        self.iov_len = len;
36    }
37
38    #[inline]
39    fn set_ptr(&mut self, ptr: *mut u8) {
40        self.iov_base = ptr as *mut c_void;
41    }
42}