<commit_before>extern crate std;
extern crate num;
extern crate uuid;

use std::net::Ipv4Addr;
use std::net::Ipv6Addr;
use self::uuid::Uuid;
use std::borrow::Cow;
use std::borrow::IntoCow;
use std::ops::Deref;

pub type SendStr = Cow<'static, str>;


#[derive(ToPrimitive, Copy)]
pub enum OpcodeRequest {
    //requests
    OpcodeStartup = 0x01,
    OpcodeCredentials = 0x04,
    OpcodeOptions = 0x05,
    OpcodeQuery = 0x07,
    OpcodePrepare = 0x09,
    OpcodeExecute = 0x0A,
    OpcodeRegister = 0x0B,
    OpcodeBatch = 0x0D
}

#[derive(Debug)]
pub enum OpcodeResponse {
    //responces
    OpcodeError = 0x00,
    OpcodeReady = 0x02,
    OpcodeAuthenticate = 0x03,
    OpcodeSupported = 0x06,
    OpcodeResult = 0x08,
    OpcodeEvent = 0x0C,

    OpcodeUnknown
}

#[derive(Debug)]
#[derive(FromPrimitive)]
pub enum KindResult {
    KindVoid = 0x0001,
    KindRows = 0x0002,
    KindSetKeyspace = 0x0003,
    KindPrepared = 0x0004,
    KindSchemaChange = 0x0005
}

pub fn opcode_response(val: u8) -> OpcodeResponse {
    match val {
        /* requests
        0x01 => OpcodeStartup,
        0x04 => OpcodeCredentials,
        0x05 => OpcodeOptions,
        0x07 => OpcodeQuery,
        0x09 => OpcodePrepare,
        0x0B => OpcodeRegister,
        */

        0x00 => OpcodeResponse::OpcodeError,
        0x02 => OpcodeResponse::OpcodeReady,
        0x03 => OpcodeResponse::OpcodeAuthenticate,
        0x06 => OpcodeResponse::OpcodeSupported,
        0x08 => OpcodeResponse::OpcodeResult,
        // 0x0A => OpcodeExecute,
        0x0C => OpcodeResponse::OpcodeEvent,

        _ => OpcodeResponse::OpcodeUnknown
    }
}


#[derive(ToPrimitive, Copy)]
pub enum Consistency {
    Any = 0x0000,
    One = 0x0001,
    Two = 0x0002,
    Three = 0x0003,
    Quorum = 0x0004,
    All = 0x0005,
    LocalQuorum = 0x0006,
    EachQuorum = 0x0007,
    Unknown,
}

#[derive(ToPrimitive, Copy)]
pub enum BatchType {
    Logged = 0x00,
    Unlogged = 0x01,
    Counter = 0x02
}

#[derive(Debug)]
pub enum CqlValueType {
    ColumnCustom = 0x0000,
    ColumnASCII = 0x0001,
    ColumnBigInt = 0x0002,
    ColumnBlob = 0x0003,
    ColumnBoolean = 0x0004,
    ColumnCounter = 0x0005,
    ColumnDecimal = 0x0006,
    ColumnDouble = 0x0007,
    ColumnFloat = 0x0008,
    ColumnInt = 0x0009,
    ColumnText = 0x000A,
    ColumnTimestamp = 0x000B,
    ColumnUuid = 0x000C,
    ColumnVarChar = 0x000D,
    ColumnVarint = 0x000E,
    ColumnTimeUuid = 0x000F,
    ColumnInet = 0x0010,
    ColumnList = 0x0020,
    ColumnMap = 0x0021,
    ColumnSet = 0x0022,
    ColumnUnknown,
}

pub fn cql_column_type(val: u16) -> CqlValueType {
    match val {
        0x0000 => CqlValueType::ColumnCustom,
        0x0001 => CqlValueType::ColumnASCII,
        0x0002 => CqlValueType::ColumnBigInt,
        0x0003 => CqlValueType::ColumnBlob,
        0x0004 => CqlValueType::ColumnBoolean,
        0x0005 => CqlValueType::ColumnCounter,
        0x0006 => CqlValueType::ColumnDecimal,
        0x0007 => CqlValueType::ColumnDouble,
        0x0008 => CqlValueType::ColumnFloat,
        0x0009 => CqlValueType::ColumnInt,
        0x000A => CqlValueType::ColumnText,
        0x000B => CqlValueType::ColumnTimestamp,
        0x000C => CqlValueType::ColumnUuid,
        0x000D => CqlValueType::ColumnVarChar,
        0x000E => CqlValueType::ColumnVarint,
        0x000F => CqlValueType::ColumnTimeUuid,
        0x0010 => CqlValueType::ColumnInet,
        0x0020 => CqlValueType::ColumnList,
        0x0021 => CqlValueType::ColumnMap,
        0x0022 => CqlValueType::ColumnSet,
        _ => CqlValueType::ColumnUnknown
    }
}


#[derive(Debug)]
pub enum RCErrorType {
    ReadError,
    WriteError,
    SerializeError,
    ConnectionError,
    NoDataError,
    GenericError,
    IOError
}

#[derive(Debug, Display)]
pub struct RCError {
    pub kind: RCErrorType,
    pub desc: SendStr,
}

impl RCError {
    pub fn new<T: IntoCow<'static, str>>(msg: T, kind: RCErrorType) -> RCError {
        RCError {
            kind: kind,
            desc: msg.into_cow()
        }
    }
    pub fn description(&self) -> &str {
        return self.desc.deref();
    }

}

impl std::error::Error for RCError {
    fn description(&self) -> &str {
        return self.desc.deref();
    }

    fn cause(&self) -> Option<&std::error::Error> {
        return None;
    }
}

impl std::fmt::Display for RCError {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
        write!(f, "Error: {}", self.desc)
    }
}

impl std::error::FromError<std::io::Error> for RCError {
    fn from_error(err: std::io::Error) -> RCError {<commit_msg>Replace usage of `std::error::FromError` by `std::convert::From`<commit_after>extern crate std;
extern crate num;
extern crate uuid;

use std::net::Ipv4Addr;
use std::net::Ipv6Addr;
use self::uuid::Uuid;
use std::borrow::Cow;
use std::borrow::IntoCow;
use std::ops::Deref;

pub type SendStr = Cow<'static, str>;


#[derive(ToPrimitive, Copy)]
pub enum OpcodeRequest {
    //requests
    OpcodeStartup = 0x01,
    OpcodeCredentials = 0x04,
    OpcodeOptions = 0x05,
    OpcodeQuery = 0x07,
    OpcodePrepare = 0x09,
    OpcodeExecute = 0x0A,
    OpcodeRegister = 0x0B,
    OpcodeBatch = 0x0D
}

#[derive(Debug)]
pub enum OpcodeResponse {
    //responces
    OpcodeError = 0x00,
    OpcodeReady = 0x02,
    OpcodeAuthenticate = 0x03,
    OpcodeSupported = 0x06,
    OpcodeResult = 0x08,
    OpcodeEvent = 0x0C,

    OpcodeUnknown
}

#[derive(Debug)]
#[derive(FromPrimitive)]
pub enum KindResult {
    KindVoid = 0x0001,
    KindRows = 0x0002,
    KindSetKeyspace = 0x0003,
    KindPrepared = 0x0004,
    KindSchemaChange = 0x0005
}

pub fn opcode_response(val: u8) -> OpcodeResponse {
    match val {
        /* requests
        0x01 => OpcodeStartup,
        0x04 => OpcodeCredentials,
        0x05 => OpcodeOptions,
        0x07 => OpcodeQuery,
        0x09 => OpcodePrepare,
        0x0B => OpcodeRegister,
        */

        0x00 => OpcodeResponse::OpcodeError,
        0x02 => OpcodeResponse::OpcodeReady,
        0x03 => OpcodeResponse::OpcodeAuthenticate,
        0x06 => OpcodeResponse::OpcodeSupported,
        0x08 => OpcodeResponse::OpcodeResult,
        // 0x0A => OpcodeExecute,
        0x0C => OpcodeResponse::OpcodeEvent,

        _ => OpcodeResponse::OpcodeUnknown
    }
}


#[derive(ToPrimitive, Copy)]
pub enum Consistency {
    Any = 0x0000,
    One = 0x0001,
    Two = 0x0002,
    Three = 0x0003,
    Quorum = 0x0004,
    All = 0x0005,
    LocalQuorum = 0x0006,
    EachQuorum = 0x0007,
    Unknown,
}

#[derive(ToPrimitive, Copy)]
pub enum BatchType {
    Logged = 0x00,
    Unlogged = 0x01,
    Counter = 0x02
}

#[derive(Debug)]
pub enum CqlValueType {
    ColumnCustom = 0x0000,
    ColumnASCII = 0x0001,
    ColumnBigInt = 0x0002,
    ColumnBlob = 0x0003,
    ColumnBoolean = 0x0004,
    ColumnCounter = 0x0005,
    ColumnDecimal = 0x0006,
    ColumnDouble = 0x0007,
    ColumnFloat = 0x0008,
    ColumnInt = 0x0009,
    ColumnText = 0x000A,
    ColumnTimestamp = 0x000B,
    ColumnUuid = 0x000C,
    ColumnVarChar = 0x000D,
    ColumnVarint = 0x000E,
    ColumnTimeUuid = 0x000F,
    ColumnInet = 0x0010,
    ColumnList = 0x0020,
    ColumnMap = 0x0021,
    ColumnSet = 0x0022,
    ColumnUnknown,
}

pub fn cql_column_type(val: u16) -> CqlValueType {
    match val {
        0x0000 => CqlValueType::ColumnCustom,
        0x0001 => CqlValueType::ColumnASCII,
        0x0002 => CqlValueType::ColumnBigInt,
        0x0003 => CqlValueType::ColumnBlob,
        0x0004 => CqlValueType::ColumnBoolean,
        0x0005 => CqlValueType::ColumnCounter,
        0x0006 => CqlValueType::ColumnDecimal,
        0x0007 => CqlValueType::ColumnDouble,
        0x0008 => CqlValueType::ColumnFloat,
        0x0009 => CqlValueType::ColumnInt,
        0x000A => CqlValueType::ColumnText,
        0x000B => CqlValueType::ColumnTimestamp,
        0x000C => CqlValueType::ColumnUuid,
        0x000D => CqlValueType::ColumnVarChar,
        0x000E => CqlValueType::ColumnVarint,
        0x000F => CqlValueType::ColumnTimeUuid,
        0x0010 => CqlValueType::ColumnInet,
        0x0020 => CqlValueType::ColumnList,
        0x0021 => CqlValueType::ColumnMap,
        0x0022 => CqlValueType::ColumnSet,
        _ => CqlValueType::ColumnUnknown
    }
}


#[derive(Debug)]
pub enum RCErrorType {
    ReadError,
    WriteError,
    SerializeError,
    ConnectionError,
    NoDataError,
    GenericError,
    IOError
}

#[derive(Debug, Display)]
pub struct RCError {
    pub kind: RCErrorType,
    pub desc: SendStr,
}

impl RCError {
    pub fn new<T: IntoCow<'static, str>>(msg: T, kind: RCErrorType) -> RCError {
        RCError {
            kind: kind,
            desc: msg.into_cow()
        }
    }
    pub fn description(&self) -> &str {
        return self.desc.deref();
    }

}

impl std::error::Error for RCError {
    fn description(&self) -> &str {
        return self.desc.deref();
    }

    fn cause(&self) -> Option<&std::error::Error> {
        return None;
    }
}

impl std::fmt::Display for RCError {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
        write!(f, "Error: {}", self.desc)
    }
}

impl std::convert::From<std::io::Error> for RCError {
    fn from(err: std::io::Error) -> RCError {
{'fraction_non_alphanumeric': 0.11738002594033722, 'fraction_numerical': 0.0737137916126243, 'mean_word_length': 2.8618530884808013, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '3564069', 'n_tokens_mistral': 3680, 'n_tokens_neox': 3281, 'n_words': 649}