<commit_before>//! Module: czmq-zframe

use {czmq_sys, Error, ErrorKind, RawInterface, Result, Sockish};
use std::{error, fmt, ptr, result, slice};
use std::ffi::{CStr, CString};
use std::os::raw::c_void;

bitflags! {
    pub flags Flags: i32 {
        const ZFRAME_MORE     = 0b00000001,
        const ZFRAME_REUSE    = 0b00000010,
        const ZFRAME_DONTWAIT = 0b00000100,
    }
}

#[derive(Eq)]
pub struct ZFrame {
    zframe: *mut czmq_sys::zframe_t,
    owned: bool,
}

unsafe impl Send for ZFrame {}
unsafe impl Sync for ZFrame {}

impl Drop for ZFrame {
    fn drop(&mut self) {
        if self.owned {
            unsafe { czmq_sys::zframe_destroy(&mut self.zframe) };
        }
    }
}

impl PartialEq for ZFrame {
    fn eq(&self, other: &ZFrame) -> bool {
        ZFrame::eq(self, other)
    }
}

impl ZFrame {
    pub fn new(data: &[u8]) -> Result<ZFrame> {
        let data_c = CString::new(data).unwrap().into_raw();
        let zframe = unsafe { czmq_sys::zframe_new(data_c as *const c_void, data.len() as u64) };
        unsafe { CString::from_raw(data_c) };

        if zframe == ptr::null_mut() {
            return Err(Error::new(ErrorKind::NullPtr, ZFrameError::Instantiate));
        }

        Ok(ZFrame {
            zframe: zframe,
            owned: true,
        })
    }

    pub fn empty() -> Result<ZFrame> {
        let zframe = unsafe { czmq_sys::zframe_new_empty() };

        if zframe == ptr::null_mut() {
            return Err(Error::new(ErrorKind::NullPtr, ZFrameError::Instantiate));
        }

        Ok(ZFrame {
            zframe: zframe,
            owned: true,<commit_msg>Don't convert byte slice to CString. That was stupid...<commit_after>//! Module: czmq-zframe

use {czmq_sys, Error, ErrorKind, RawInterface, Result, Sockish};
use std::{error, fmt, ptr, result, slice};
use std::ffi::{CStr, CString};
use std::os::raw::c_void;

bitflags! {
    pub flags Flags: i32 {
        const ZFRAME_MORE     = 0b00000001,
        const ZFRAME_REUSE    = 0b00000010,
        const ZFRAME_DONTWAIT = 0b00000100,
    }
}

#[derive(Eq)]
pub struct ZFrame {
    zframe: *mut czmq_sys::zframe_t,
    owned: bool,
}

unsafe impl Send for ZFrame {}
unsafe impl Sync for ZFrame {}

impl Drop for ZFrame {
    fn drop(&mut self) {
        if self.owned {
            unsafe { czmq_sys::zframe_destroy(&mut self.zframe) };
        }
    }
}

impl PartialEq for ZFrame {
    fn eq(&self, other: &ZFrame) -> bool {
        ZFrame::eq(self, other)
    }
}

impl ZFrame {
    pub fn new(data: &[u8]) -> Result<ZFrame> {
        let zframe = unsafe { czmq_sys::zframe_new(data.as_ptr() as *const c_void, data.len() as u64) };

        if zframe == ptr::null_mut() {
            return Err(Error::new(ErrorKind::NullPtr, ZFrameError::Instantiate));
        }

        Ok(ZFrame {
            zframe: zframe,
            owned: true,
        })
    }

    pub fn empty() -> Result<ZFrame> {
        let zframe = unsafe { czmq_sys::zframe_new_empty() };

        if zframe == ptr::null_mut() {
            return Err(Error::new(ErrorKind::NullPtr, ZFrameError::Instantiate));
        }

        Ok(ZFrame {
            zframe: zframe,
            owned: true,
{'fraction_non_alphanumeric': 0.1349056603773585, 'fraction_numerical': 0.02012578616352201, 'mean_word_length': 2.427801724137931, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1721403', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1090, 'n_words': 260}