pub struct K(/* private fields */);Expand description
Struct representing q object.
Implementations§
Source§impl K
impl K
Sourcepub fn new_bool(boolean: bool) -> Self
pub fn new_bool(boolean: bool) -> Self
Construct q bool from bool.
§Example
use kdb_codec::*;
fn main() {
let q_bool_false = K::new_bool(false);
assert_eq!(format!("{}", q_bool_false), String::from("0b"));
}Sourcepub fn new_guid(guid: [G; 16]) -> Self
pub fn new_guid(guid: [G; 16]) -> Self
Construct q GUID from [u8; 16].
§Example
use kdb_codec::*;
fn main() {
let q_guid = K::new_guid([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
assert_eq!(
format!("{}", q_guid),
String::from("01020304-0506-0708-090a-0b0c0d0e0f10")
);
}Sourcepub fn new_byte(byte: u8) -> Self
pub fn new_byte(byte: u8) -> Self
Construct q byte from u8.
§Example
use kdb_codec::*;
fn main() {
let q_byte = K::new_byte(0x9e);
assert_eq!(format!("{}", q_byte), String::from("0x9e"));
}Sourcepub fn new_short(short: i16) -> Self
pub fn new_short(short: i16) -> Self
Construct q short from i16.
§Example
use kdb_codec::*;
fn main() {
let q_short = K::new_short(17);
assert_eq!(format!("{}", q_short), String::from("17h"));
}Sourcepub fn new_int(int: i32) -> Self
pub fn new_int(int: i32) -> Self
Construct q int from i32.
§Example
use kdb_codec::*;
fn main() {
let q_int = K::new_int(-256);
assert_eq!(format!("{}", q_int), String::from("-256i"));
}Sourcepub fn new_long(long: i64) -> Self
pub fn new_long(long: i64) -> Self
Construct q long from i64.
§Example
use kdb_codec::*;
fn main() {
let q_long = K::new_long(86400000000000);
assert_eq!(format!("{}", q_long), String::from("86400000000000"));
}Sourcepub fn new_real(real: f32) -> Self
pub fn new_real(real: f32) -> Self
Construct q real from f32.
§Example
use kdb_codec::*;
fn main() {
let q_real = K::new_real(0.25);
assert_eq!(format!("{:.2}", q_real), String::from("0.25e"));
}Sourcepub fn new_float(float: f64) -> Self
pub fn new_float(float: f64) -> Self
Construct q float from f64.
§Example
use kdb_codec::*;
fn main() {
let q_float = K::new_float(113.0456);
assert_eq!(format!("{:.7}", q_float), String::from("113.0456000"));
}Sourcepub fn new_char(character: char) -> Self
pub fn new_char(character: char) -> Self
Construct q char from char.
§Example
use kdb_codec::*;
fn main() {
let q_char = K::new_char('r');
assert_eq!(format!("{}", q_char), String::from("\"r\""));
}Sourcepub fn new_symbol(symbol: String) -> Self
pub fn new_symbol(symbol: String) -> Self
Construct q symbol from String.
§Example
use kdb_codec::*;
fn main() {
let q_symbol = K::new_symbol(String::from("Jordan"));
assert_eq!(format!("{}", q_symbol), String::from("`Jordan"));
}Sourcepub fn new_timestamp(timestamp: DateTime<Utc>) -> Self
pub fn new_timestamp(timestamp: DateTime<Utc>) -> Self
Construct q timestamp from DateTime<Utc>. If the DateTime value is not between
1677-09-21T00:12:43.145224192 and 2262-04-11T23:47:16.854775807, it returns 0Np in q/kdb+.
§Note
For the range of valid DateTime, see chrono.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let q_timestamp = K::new_timestamp(
NaiveDate::from_ymd_opt(2019, 5, 9)
.unwrap()
.and_hms_nano_opt(0, 39, 2, 194756)
.unwrap()
.and_local_timezone(Utc)
.unwrap(),
);
assert_eq!(
format!("{}", q_timestamp),
String::from("2019.05.09D00:39:02.000194756")
);
}Sourcepub fn new_month(month: NaiveDate) -> Self
pub fn new_month(month: NaiveDate) -> Self
Construct q month from Date<Utc>.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let q_month = K::new_month(NaiveDate::from_ymd_opt(2019, 12, 15).unwrap());
assert_eq!(format!("{}", q_month), String::from("2019.12m"));
}Sourcepub fn new_date(date: NaiveDate) -> Self
pub fn new_date(date: NaiveDate) -> Self
Construct q date from Date<Utc>.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let q_date = K::new_date(NaiveDate::from_ymd_opt(2012, 3, 12).unwrap());
assert_eq!(format!("{}", q_date), String::from("2012.03.12"));
}Sourcepub fn new_datetime(datetime: DateTime<Utc>) -> Self
pub fn new_datetime(datetime: DateTime<Utc>) -> Self
Construct q datetime from DateTime<Utc>.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let q_datetime = K::new_datetime(
NaiveDate::from_ymd_opt(2013, 1, 10)
.unwrap()
.and_hms_milli_opt(0, 9, 50, 38)
.unwrap()
.and_local_timezone(Utc)
.unwrap(),
);
assert_eq!(
format!("{}", q_datetime),
String::from("2013.01.10T00:09:50.038")
);
}Sourcepub fn new_timespan(duration: Duration) -> Self
pub fn new_timespan(duration: Duration) -> Self
Construct q timespan from Duration.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let q_timespan = K::new_timespan(Duration::nanoseconds(102899277539844));
assert_eq!(
format!("{}", q_timespan),
String::from("1D04:34:59.277539844")
);
}Sourcepub fn new_minute(minute: Duration) -> Self
pub fn new_minute(minute: Duration) -> Self
Construct q minute from Duration.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let q_minute = K::new_minute(Duration::minutes(99));
assert_eq!(format!("{}", q_minute), String::from("01:39"));
}Sourcepub fn new_second(second: Duration) -> Self
pub fn new_second(second: Duration) -> Self
Construct q second from Duration.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let q_second = K::new_second(Duration::seconds(3702));
assert_eq!(format!("{}", q_second), String::from("01:01:42"));
}Sourcepub fn new_time(time: Duration) -> Self
pub fn new_time(time: Duration) -> Self
Construct q time from Duration.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let q_time = K::new_time(Duration::milliseconds(27843489));
assert_eq!(format!("{}", q_time), String::from("07:44:03.489"));
}Sourcepub fn new_bool_list(list: Vec<bool>, attribute: i8) -> Self
pub fn new_bool_list(list: Vec<bool>, attribute: i8) -> Self
Construct q bool list from Vec<bool>.
§Example
use kdb_codec::*;
fn main() {
let q_bool_list = K::new_bool_list(vec![true, false, true], qattribute::NONE);
assert_eq!(format!("{}", q_bool_list), String::from("101b"));
}Sourcepub fn new_guid_list(list: Vec<[u8; 16]>, attribute: i8) -> Self
pub fn new_guid_list(list: Vec<[u8; 16]>, attribute: i8) -> Self
Construct q GUID list from Vec<U>.
§Example
use kdb_codec::*;
fn main() {
let q_guid_list = K::new_guid_list(
vec![
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
[
240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
],
],
qattribute::NONE,
);
assert_eq!(
format!("{}", q_guid_list),
String::from(
"00010203-0405-0607-0809-0a0b0c0d0e0f f0f1f2f3-f4f5-f6f7-f8f9-fafbfcfdfeff"
)
);
}Sourcepub fn new_byte_list(list: Vec<u8>, attribute: i8) -> Self
pub fn new_byte_list(list: Vec<u8>, attribute: i8) -> Self
Construct q byte list from Vec<G>.
§Example
use kdb_codec::*;
fn main() {
let q_byte_list = K::new_byte_list(vec![7, 12, 21, 144], qattribute::NONE);
assert_eq!(format!("{}", q_byte_list), String::from("0x070c1590"));
}Sourcepub fn new_short_list(list: Vec<i16>, attribute: i8) -> Self
pub fn new_short_list(list: Vec<i16>, attribute: i8) -> Self
Construct q short list from Vec<H>.
§Example
use kdb_codec::*;
fn main() {
let q_short_list =
K::new_short_list(vec![qnull::SHORT, -7, 12, 21, 144], qattribute::SORTED);
assert_eq!(
format!("{}", q_short_list),
String::from("`s#0N -7 12 21 144h")
);
}Sourcepub fn new_int_list(list: Vec<i32>, attribute: i8) -> Self
pub fn new_int_list(list: Vec<i32>, attribute: i8) -> Self
Construct q int list from Vec<I>.
§Example
use kdb_codec::*;
fn main() {
let q_int_list = K::new_int_list(
vec![-10000, -10000, 21, 21, qinf::INT, 144000],
qattribute::PARTED,
);
assert_eq!(
format!("{}", q_int_list),
String::from("`p#-10000 -10000 21 21 0W 144000i")
);
}Sourcepub fn new_long_list(list: Vec<i64>, attribute: i8) -> Self
pub fn new_long_list(list: Vec<i64>, attribute: i8) -> Self
Construct q long list from Vec<J>.
§Example
use kdb_codec::*;
fn main() {
let q_long_list = K::new_long_list(vec![-86400000000000], qattribute::UNIQUE);
assert_eq!(
format!("{}", q_long_list),
String::from("`u#,-86400000000000")
);
}Sourcepub fn new_real_list(list: Vec<f32>, attribute: i8) -> Self
pub fn new_real_list(list: Vec<f32>, attribute: i8) -> Self
Construct q real list from Vec<E>.
§Example
use kdb_codec::*;
fn main() {
let q_real_list = K::new_real_list(vec![30.2, 5.002], qattribute::NONE);
assert_eq!(format!("{:.3}", q_real_list), String::from("30.200 5.002e"));
}Sourcepub fn new_float_list(list: Vec<f64>, attribute: i8) -> Self
pub fn new_float_list(list: Vec<f64>, attribute: i8) -> Self
Construct q float list from Vec<F>.
§Example
use kdb_codec::*;
fn main() {
let q_float_list = K::new_float_list(
vec![100.23, 0.4268, qnull::FLOAT, 15.882, qninf::FLOAT],
qattribute::NONE,
);
assert_eq!(
format!("{}", q_float_list),
String::from("100.23 0.4268 0n 15.882 -0w")
);
}Sourcepub fn new_string(string: String, attribute: i8) -> Self
pub fn new_string(string: String, attribute: i8) -> Self
Sourcepub fn new_symbol_list(list: Vec<String>, attribute: i8) -> Self
pub fn new_symbol_list(list: Vec<String>, attribute: i8) -> Self
Construct q symbol list from Vec<String>.
§Example
use kdb_codec::*;
fn main() {
let q_symbol_list = K::new_symbol_list(
vec![
String::from("a"),
String::from("b"),
String::from("a"),
String::from("c"),
],
qattribute::GROUPED,
);
assert_eq!(format!("{}", q_symbol_list), String::from("`g#`a`b`a`c"));
}Sourcepub fn new_timestamp_list(list: Vec<DateTime<Utc>>, attribute: i8) -> Self
pub fn new_timestamp_list(list: Vec<DateTime<Utc>>, attribute: i8) -> Self
Construct q timestamp list from Vec<DateTime<Utc>>. If the DateTime value is not between
1677-09-21T00:12:43.145224192 and 2262-04-11T23:47:16.854775807, it returns 0Np in q/kdb+.
§Note
For the range of valid DateTime, see chrono.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let q_timestamp_list = K::new_timestamp_list(
vec![
*qnull::TIMESTAMP,
NaiveDate::from_ymd_opt(2000, 2, 6)
.unwrap()
.and_hms_nano_opt(5, 11, 28, 4032)
.unwrap()
.and_local_timezone(Utc)
.unwrap(),
*qinf::TIMESTAMP,
],
qattribute::NONE,
);
assert_eq!(
format!("{}", q_timestamp_list),
String::from("0N 2000.02.06D05:11:28.000004032 0Wp")
);
}Sourcepub fn new_month_list(list: Vec<NaiveDate>, attribute: i8) -> Self
pub fn new_month_list(list: Vec<NaiveDate>, attribute: i8) -> Self
Construct q month list from Vec<Date<Utc>>.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let q_month_list = K::new_month_list(
vec![
NaiveDate::from_ymd_opt(2006, 3, 9).unwrap(),
NaiveDate::from_ymd_opt(1999, 5, 31).unwrap(),
qnull::MONTH,
],
qattribute::NONE,
);
assert_eq!(
format!("{}", q_month_list),
String::from("2006.03 1999.05 0Nm")
);
}Sourcepub fn new_date_list(list: Vec<NaiveDate>, attribute: i8) -> Self
pub fn new_date_list(list: Vec<NaiveDate>, attribute: i8) -> Self
Construct q date list from Vec<Date<Utc>>.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let q_date_list = K::new_date_list(
vec![
NaiveDate::from_ymd_opt(2001, 2, 18).unwrap(),
NaiveDate::from_ymd_opt(2019, 12, 12).unwrap(),
qinf::DATE,
NaiveDate::from_ymd_opt(2003, 10, 16).unwrap(),
],
qattribute::NONE,
);
assert_eq!(
format!("{}", q_date_list),
String::from("2001.02.18 2019.12.12 0W 2003.10.16")
);
}Sourcepub fn new_datetime_list(list: Vec<DateTime<Utc>>, attribute: i8) -> Self
pub fn new_datetime_list(list: Vec<DateTime<Utc>>, attribute: i8) -> Self
Construct q datetime list from Vec<DateTime<Utc>>.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let q_datetime_list = K::new_datetime_list(
vec![
NaiveDate::from_ymd_opt(2002, 1, 26)
.unwrap()
.and_hms_nano_opt(9, 39, 2, 368376238)
.unwrap()
.and_local_timezone(Utc)
.unwrap(),
*qinf::DATETIME,
],
qattribute::SORTED,
);
assert_eq!(
format!("{}", q_datetime_list),
String::from("`s#2002.01.26T09:39:02.368 0Wz")
);
}Sourcepub fn new_timespan_list(list: Vec<Duration>, attribute: i8) -> Self
pub fn new_timespan_list(list: Vec<Duration>, attribute: i8) -> Self
Construct q timespan list from Vec<Duration>.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let q_timespan_list = K::new_timespan_list(
vec![
*qinf::TIMESPAN,
Duration::nanoseconds(7240514990625504),
Duration::nanoseconds(-107695363440640000),
],
qattribute::NONE,
);
assert_eq!(
format!("{}", q_timespan_list),
String::from("0W 83D19:15:14.990625504 -1246D11:22:43.440640000")
);
}Sourcepub fn new_minute_list(list: Vec<Duration>, attribute: i8) -> Self
pub fn new_minute_list(list: Vec<Duration>, attribute: i8) -> Self
Construct q minute list from Vec<Duration>.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let q_minute_list = K::new_minute_list(
vec![Duration::minutes(504), Duration::seconds(-100)],
qattribute::NONE,
);
assert_eq!(format!("{}", q_minute_list), String::from("08:24 -00:01"));
}Sourcepub fn new_second_list(list: Vec<Duration>, attribute: i8) -> Self
pub fn new_second_list(list: Vec<Duration>, attribute: i8) -> Self
Construct q second list from Vec<Duration>.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let q_second_list = K::new_second_list(
vec![
Duration::seconds(-3554),
*qinf::SECOND,
Duration::seconds(13744),
*qninf::SECOND,
*qnull::SECOND,
],
qattribute::NONE,
);
assert_eq!(
format!("{}", q_second_list),
String::from("-00:59:14 0W 03:49:04 -0W 0Nv")
);
}Sourcepub fn new_time_list(list: Vec<Duration>, attribute: i8) -> Self
pub fn new_time_list(list: Vec<Duration>, attribute: i8) -> Self
Construct q time list from Vec<Duration>.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let q_time_list = K::new_time_list(
vec![
Duration::milliseconds(642982),
Duration::milliseconds(789848),
*qninf::TIME,
Duration::milliseconds(58725553),
],
qattribute::NONE,
);
assert_eq!(
format!("{}", q_time_list),
String::from("00:10:42.982 00:13:09.848 -0W 16:18:45.553")
);
}Sourcepub fn new_compound_list(list: Vec<K>) -> Self
pub fn new_compound_list(list: Vec<K>) -> Self
Construct q compound list from Vec<K>.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let q_compound_list = K::new_compound_list(vec![
K::new_symbol_list(
vec![
String::from("Ruby"),
String::from("Diamond"),
String::from("Sapphire"),
],
qattribute::UNIQUE,
),
K::new_timestamp(*qnull::TIMESTAMP),
K::new_long_list(vec![0, 1, 2, qninf::LONG], qattribute::NONE),
K::new_month_list(
vec![NaiveDate::from_ymd_opt(2004, 2, 7).unwrap()],
qattribute::NONE,
),
]);
assert_eq!(
format!("{}", q_compound_list),
String::from("(`u#`Ruby`Diamond`Sapphire;0Np;0 1 2 -0W;,2004.02m)")
);
}Sourcepub fn new_dictionary(keys: K, values: K) -> Result<Self>
pub fn new_dictionary(keys: K, values: K) -> Result<Self>
Construct q dictionary from a pair of keys (K) and values (K).
§Example
use kdb_codec::*;
fn main() {
let keys = K::new_int_list(vec![20, 30, 40], qattribute::SORTED);
let values = K::new_bool_list(vec![false, false, true], qattribute::NONE);
let q_dictionary = K::new_dictionary(keys, values).unwrap();
assert_eq!(
format!("{}", q_dictionary),
String::from("`s#20 30 40i!001b")
);
}§Note
This constructor can return an error object whose type is qtype::ERROR. In that case the error message can be
retrieved by get_symbol.
Sourcepub fn new_null() -> Self
pub fn new_null() -> Self
Construct q null.
§Example
use kdb_codec::*;
fn main() {
let q_null = K::new_null();
assert_eq!(format!("{}", q_null), String::from("::"));
}Sourcepub fn new_error(error: String) -> Self
pub fn new_error(error: String) -> Self
Construct q error object.
§Example
use kdb_codec::*;
fn main(){
let q_error=K::new_error(String::from("woops"));
assert_eq!(format!("{}", q_error), String::from("'woops"));
}Sourcepub fn get_bool(&self) -> Result<bool>
pub fn get_bool(&self) -> Result<bool>
Get underlying bool value.
§Example
use kdb_codec::*;
fn main() {
let q_bool = K::new_bool(true);
assert_eq!(q_bool.get_bool(), Ok(true));
}Sourcepub fn get_guid(&self) -> Result<[u8; 16]>
pub fn get_guid(&self) -> Result<[u8; 16]>
Get underlying [u8; 16] value.
§Example
use kdb_codec::*;
fn main() {
let q_guid = K::new_guid([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
assert_eq!(
q_guid.get_guid(),
Ok([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
);
}Sourcepub fn get_byte(&self) -> Result<u8>
pub fn get_byte(&self) -> Result<u8>
Get underlying u8 value. Compatible types are:
- bool
- byte
- char
§Example
use kdb_codec::*;
fn main() {
let q_byte = K::new_byte(0x77);
assert_eq!(q_byte.get_byte(), Ok(0x77));
}Sourcepub fn get_short(&self) -> Result<i16>
pub fn get_short(&self) -> Result<i16>
Get underlying i16 value.
§Example
use kdb_codec::*;
fn main() {
let q_short = K::new_short(-12);
assert_eq!(q_short.get_short(), Ok(-12));
}Sourcepub fn get_int(&self) -> Result<i32>
pub fn get_int(&self) -> Result<i32>
Get underlying i32 value. Compatible types are:
- int
- month
- date
- minute
- second
- time
§Example
use kdb_codec::*;
fn main() {
let q_int = K::new_int(144000);
assert_eq!(q_int.get_int(), Ok(144000));
}Sourcepub fn get_long(&self) -> Result<i64>
pub fn get_long(&self) -> Result<i64>
Get underlying i64 value. Compatible types are:
- long
- timestamp
- timespan
§Example
use kdb_codec::*;
fn main() {
let q_long = K::new_long(86400000000000);
assert_eq!(q_long.get_long(), Ok(86400000000000));
}Sourcepub fn get_real(&self) -> Result<f32>
pub fn get_real(&self) -> Result<f32>
Get underlying f32 value.
§Example
use kdb_codec::*;
fn main() {
let q_real = K::new_real(0.25);
assert_eq!(q_real.get_real(), Ok(0.25));
}Sourcepub fn get_float(&self) -> Result<f64>
pub fn get_float(&self) -> Result<f64>
Get underlying i32 value. Compatible types are:
- float
- datetime
§Example
use kdb_codec::*;
fn main() {
let q_float = K::new_float(1000.23456);
assert_eq!(q_float.get_float(), Ok(1000.23456));
}Sourcepub fn get_char(&self) -> Result<char>
pub fn get_char(&self) -> Result<char>
Get underlying char value.
§Example
use kdb_codec::*;
fn main() {
let q_char = K::new_char('C');
assert_eq!(q_char.get_char(), Ok('C'));
}Sourcepub fn get_symbol(&self) -> Result<&str>
pub fn get_symbol(&self) -> Result<&str>
Get underlying i32 value.
§Example
use kdb_codec::*;
fn main() {
let q_symbol = K::new_symbol(String::from("Rust"));
assert_eq!(q_symbol.get_symbol(), Ok("Rust"));
}Sourcepub fn get_timestamp(&self) -> Result<DateTime<Utc>>
pub fn get_timestamp(&self) -> Result<DateTime<Utc>>
Get underlying timestamp value as DateTime<Utc>.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let q_timestamp = K::new_timestamp(
NaiveDate::from_ymd_opt(2001, 9, 15)
.unwrap()
.and_hms_nano_opt(4, 2, 30, 37204)
.unwrap()
.and_local_timezone(Utc)
.unwrap(),
);
assert_eq!(
q_timestamp.get_timestamp(),
Ok(NaiveDate::from_ymd_opt(2001, 9, 15)
.unwrap()
.and_hms_nano_opt(4, 2, 30, 37204)
.unwrap()
.and_local_timezone(Utc)
.unwrap())
);
}Sourcepub fn get_month(&self) -> Result<NaiveDate>
pub fn get_month(&self) -> Result<NaiveDate>
Get underlying month value as Date<Utc>.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let q_month = K::new_month(NaiveDate::from_ymd_opt(2007, 8, 30).unwrap());
assert_eq!(
q_month.get_month(),
Ok(NaiveDate::from_ymd_opt(2007, 8, 1).unwrap())
);
}Sourcepub fn get_date(&self) -> Result<NaiveDate>
pub fn get_date(&self) -> Result<NaiveDate>
Get underlying date value as Date<Utc>.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let q_date = K::new_date(NaiveDate::from_ymd_opt(2000, 5, 10).unwrap());
assert_eq!(
q_date.get_date(),
Ok(NaiveDate::from_ymd_opt(2000, 5, 10).unwrap())
);
}Sourcepub fn get_datetime(&self) -> Result<DateTime<Utc>>
pub fn get_datetime(&self) -> Result<DateTime<Utc>>
Get underlying datetime value as DateTime<Utc>.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let q_datetime = K::new_datetime(
NaiveDate::from_ymd_opt(2011, 4, 7)
.unwrap()
.and_hms_milli_opt(19, 5, 41, 385)
.unwrap()
.and_local_timezone(Utc)
.unwrap(),
);
assert_eq!(
q_datetime.get_datetime(),
Ok(NaiveDate::from_ymd_opt(2011, 4, 7)
.unwrap()
.and_hms_milli_opt(19, 5, 41, 385)
.unwrap()
.and_local_timezone(Utc)
.unwrap())
);
}Sourcepub fn get_timespan(&self) -> Result<Duration>
pub fn get_timespan(&self) -> Result<Duration>
Get underlying timespan value as Duration.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let q_timespan = K::new_timespan(Duration::nanoseconds(131400000000000));
assert_eq!(
q_timespan.get_timespan(),
Ok(Duration::nanoseconds(131400000000000))
);
}Sourcepub fn get_minute(&self) -> Result<Duration>
pub fn get_minute(&self) -> Result<Duration>
Get underlying minute value as Duration.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let q_minute = K::new_minute(Duration::minutes(30));
assert_eq!(q_minute.get_minute(), Ok(Duration::minutes(30)));
}Sourcepub fn get_second(&self) -> Result<Duration>
pub fn get_second(&self) -> Result<Duration>
Get underlying second value as Duration.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let q_second = K::new_second(Duration::seconds(30));
assert_eq!(q_second.get_second(), Ok(Duration::seconds(30)));
}Sourcepub fn get_time(&self) -> Result<Duration>
pub fn get_time(&self) -> Result<Duration>
Get underlying time value as Duration.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let q_time = K::new_time(Duration::milliseconds(3000));
assert_eq!(q_time.get_time(), Ok(Duration::milliseconds(3000)));
}Sourcepub fn get_dictionary(&self) -> Result<&K>
pub fn get_dictionary(&self) -> Result<&K>
Get underlying immutable dictionary (flipped table) of table type as K.
§Example
use kdb_codec::*;
fn main() {
let headers = K::new_symbol_list(
vec![String::from("fruit"), String::from("price")],
qattribute::NONE,
);
let columns = K::new_compound_list(vec![
K::new_symbol_list(
vec![
String::from("strawberry"),
String::from("orange"),
qnull::SYMBOL,
],
qattribute::PARTED,
),
K::new_float_list(vec![2.5, 1.25, 117.8], qattribute::NONE),
]);
let q_dictionary = K::new_dictionary(headers, columns).unwrap();
let q_table = q_dictionary.flip().unwrap();
assert_eq!(
format!("{}", q_table.get_dictionary().unwrap()),
String::from("`fruit`price!(`p#`strawberry`orange`;2.5 1.25 117.8)")
);
}Sourcepub fn get_mut_dictionary(&mut self) -> Result<&mut K>
pub fn get_mut_dictionary(&mut self) -> Result<&mut K>
Get underlying mutable dictionary (flipped table) of table type as K.
§Example
use kdb_codec::*;
fn main() {
let headers = K::new_symbol_list(
vec![String::from("fruit"), String::from("price")],
qattribute::NONE,
);
let columns = K::new_compound_list(vec![
K::new_symbol_list(
vec![
String::from("strawberry"),
String::from("orange"),
qnull::SYMBOL,
],
qattribute::PARTED,
),
K::new_float_list(vec![2.5, 1.25, 117.8], qattribute::NONE),
]);
let q_dictionary = K::new_dictionary(headers, columns).unwrap();
let mut q_table = q_dictionary.flip().unwrap();
let inner = q_table.get_mut_dictionary().unwrap();
// modify inner dictionary
inner.as_mut_vec::<K>().unwrap()[0]
.push(&String::from("color"))
.unwrap();
inner.as_mut_vec::<K>().unwrap()[1]
.push(&K::new_string(String::from("RO"), qattribute::NONE))
.unwrap();
assert_eq!(
format!("{}", q_table),
String::from("+`fruit`price`color!(`p#`strawberry`orange`;2.5 1.25 117.8;\"RO\")")
);
}Sourcepub fn get_error_string(&self) -> Result<&str>
pub fn get_error_string(&self) -> Result<&str>
Get underlying error value as String.
§Example
use kdb_codec::*;
#[tokio::main]
async fn main() -> Result<()> {
let mut socket = QStream::connect(ConnectionMethod::TCP, "localhost", 5001, "kdbuser:pass")
.await
.expect("Failed to connect");
let result = socket.send_sync_message(&"1+`a").await?;
assert_eq!(result.get_error_string(), Ok("type"));
Ok(())
}Sourcepub fn as_string(&self) -> Result<&str>
pub fn as_string(&self) -> Result<&str>
Get underlying immutable String value.
§Example
use kdb_codec::*;
fn main() {
let string = K::new_string(String::from("something"), qattribute::NONE);
assert_eq!(string.as_string().unwrap(), "something");
}Sourcepub fn as_mut_string(&mut self) -> Result<&mut String>
pub fn as_mut_string(&mut self) -> Result<&mut String>
Sourcepub fn as_mut_vec<T>(&mut self) -> Result<&mut Vec<T>>where
T: 'static,
pub fn as_mut_vec<T>(&mut self) -> Result<&mut Vec<T>>where
T: 'static,
Get the underlying mutable vector. If the specified type is wrong, it returns an empty vector.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let mut timestamp_list = K::new_timestamp_list(
vec![
Utc.ymd(2018, 2, 18).and_hms_nano(4, 0, 0, 100),
Utc.ymd(2019, 12, 3).and_hms_nano(4, 5, 10, 3456),
],
qattribute::NONE,
);
timestamp_list
.as_mut_vec::<J>()
.unwrap()
.push(682184439000046395);
assert_eq!(format!("{}", timestamp_list), String::from("2018.02.18D04:00:00.000000100 2019.12.03D04:05:10.000003456 2021.08.13D15:40:39.000046395"));
}Sourcepub fn as_vec<T>(&self) -> Result<&Vec<T>>where
T: 'static,
pub fn as_vec<T>(&self) -> Result<&Vec<T>>where
T: 'static,
Get the underlying immutable vector. If the specified type is wrong, it returns an empty vector.
§Example
use kdb_codec::*;
fn main(){
let bool_list=K::new_bool_list(vec![true, false], qattribute::UNIQUE);
assert_eq!(*bool_list.as_vec::<G>().unwrap(), vec![1_u8, 0]);
}Sourcepub fn get_column<T>(&self, column: T) -> Result<&K>where
T: ToString,
pub fn get_column<T>(&self, column: T) -> Result<&K>where
T: ToString,
Get an immutable column of a table with a specified name.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let header = K::new_symbol_list(
vec![String::from("time"), String::from("sym")],
qattribute::NONE,
);
let time_column = K::new_timestamp_list(
vec![
Utc.ymd(2019, 4, 10).and_hms_nano(3, 19, 48, 1234),
Utc.ymd(2019, 4, 10).and_hms_nano(3, 21, 30, 948532),
],
qattribute::NONE,
);
let sym_column = K::new_symbol_list(
vec![String::from("eggplant"), String::from("tomato")],
qattribute::NONE,
);
let table = K::new_dictionary(header, K::new_compound_list(vec![time_column, sym_column]))
.unwrap()
.flip()
.unwrap();
let syms = table.get_column("sym").unwrap();
println!("syms: {}", syms);
}Sourcepub fn get_mut_column<T>(&mut self, column: T) -> Result<&mut K>where
T: ToString,
pub fn get_mut_column<T>(&mut self, column: T) -> Result<&mut K>where
T: ToString,
Get a mutable column of a table with a specified name.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let header = K::new_symbol_list(
vec![String::from("time"), String::from("sym")],
qattribute::NONE,
);
let time_column = K::new_timestamp_list(
vec![
Utc.ymd(2019, 4, 10).and_hms_nano(3, 19, 48, 1234),
Utc.ymd(2019, 4, 10).and_hms_nano(3, 21, 30, 948532),
],
qattribute::NONE,
);
let sym_column = K::new_symbol_list(
vec![String::from("eggplant"), String::from("tomato")],
qattribute::NONE,
);
let mut table =
K::new_dictionary(header, K::new_compound_list(vec![time_column, sym_column]))
.unwrap()
.flip()
.unwrap();
let mut syms = table.get_mut_column("sym").unwrap();
println!("syms: {}", syms);
let _ = std::mem::replace(
syms,
K::new_symbol_list(
vec![String::from("banana"), String::from("strawberry")],
qattribute::NONE,
),
);
println!("table: {}", table);
}Sourcepub fn get_type(&self) -> i8
pub fn get_type(&self) -> i8
Get a type of q object.
§Example
use kdb_codec::*;
use kdb_codec::*;
fn main() {
let q_int = K::new_int(12);
assert_eq!(q_int.get_type(), qtype::INT_ATOM);
}Sourcepub fn get_attribute(&self) -> i8
pub fn get_attribute(&self) -> i8
Get an attribute of q object.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let timestamp_list = K::new_timestamp_list(
vec![
Utc.ymd(2021, 3, 9).and_hms_nano(12, 5, 40, 67824),
Utc.ymd(2021, 3, 13).and_hms_nano(5, 47, 2, 260484387),
],
qattribute::SORTED,
);
assert_eq!(timestamp_list.get_attribute(), qattribute::SORTED);
}Sourcepub fn set_attribute(&mut self, attribute: i8)
pub fn set_attribute(&mut self, attribute: i8)
Set an attribute to the underlying q object.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let mut timestamp_list = K::new_timestamp_list(
vec![Utc.ymd(2021, 3, 9).and_hms_nano(12, 5, 40, 67824)],
qattribute::NONE,
);
assert_eq!(timestamp_list.get_attribute(), qattribute::NONE);
// Push timestamp
timestamp_list
.push(&Utc.ymd(2021, 3, 13).and_hms_nano(5, 47, 2, 260484387))
.unwrap();
timestamp_list.set_attribute(qattribute::SORTED);
assert_eq!(timestamp_list.get_attribute(), qattribute::SORTED);
}§Note
The validity of the attribute is not checked. For example, if you set a sorted attribute to an unsorted list, it does not return an error. It will fail in q process.
Sourcepub fn push(&mut self, element: &dyn Any) -> Result<()>
pub fn push(&mut self, element: &dyn Any) -> Result<()>
Add an element to the tail of the underlying list.
§Parameters
element: An element to insert. The type needs to be a one used for atom constructorK::new_*. For example, int element must be ai32type and timestamp element must be aDateTime<Utc>type.
§Example
use kdb_codec::*;
fn main() {
let mut symbol_list = K::new_symbol_list(vec![String::from("first")], qattribute::NONE);
symbol_list.push(&String::from("second")).unwrap();
if let Err(error) = symbol_list.push(&12) {
eprintln!("Oh no!! {}", error);
}
assert_eq!(
*symbol_list.as_vec::<S>().unwrap(),
vec![String::from("first"), String::from("second")]
);
let mut string_list = K::new_compound_list(vec![K::new_string(
String::from("string"),
qattribute::NONE,
)]);
string_list.push(&K::new_bool(false)).unwrap();
assert_eq!(format!("{}", string_list), String::from("(\"string\";0b)"));
}§Note
If the DateTime value for timestamp is not between 1677-09-21T00:12:43.145224192 and 2262-04-11T23:47:16.854775807, it returns 0Np in q/kdb+.
§Note
For the range of valid DateTime, see chrono.
Sourcepub fn insert(&mut self, index: usize, element: &dyn Any) -> Result<()>
pub fn insert(&mut self, index: usize, element: &dyn Any) -> Result<()>
Insert an element to the underlying q list at the specified location by an index.
§Parameters
index: Index of the location where the new element is inserted.element: An element to insert. The type needs to be a one used for atom constructorK::new_*. For example, int element must be ai32type and timestamp element must be aDateTime<Utc>type.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let mut q_symbol_list = K::new_symbol_list(vec![String::from("almond")], qattribute::NONE);
q_symbol_list.push(&String::from("hazel")).unwrap();
q_symbol_list.insert(1, &String::from("macadamia")).unwrap();
assert_eq!(
*q_symbol_list.as_vec::<S>().unwrap(),
vec![
String::from("almond"),
String::from("macadamia"),
String::from("hazel")
]
);
let mut q_minute_list = K::new_minute_list(vec![Duration::minutes(1024)], qattribute::NONE);
q_minute_list.insert(0, &Duration::minutes(12)).unwrap();
assert_eq!(*q_minute_list.as_vec::<I>().unwrap(), vec![12, 1024]);
}Sourcepub fn pop_bool(&mut self) -> Result<bool>
pub fn pop_bool(&mut self) -> Result<bool>
Pop a bool object from q bool list.
§Example
use kdb_codec::*;
fn main() {
let mut q_bool_list = K::new_bool_list(vec![false, true], qattribute::NONE);
let tail = q_bool_list.pop_bool().unwrap();
assert_eq!(tail, true);
}Sourcepub fn pop_guid(&mut self) -> Result<[u8; 16]>
pub fn pop_guid(&mut self) -> Result<[u8; 16]>
Pop a [u8; 16] object from q GUID list.
§Example
use kdb_codec::*;
fn main() {
let mut q_guid_list = K::new_guid_list(
vec![[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]],
qattribute::NONE,
);
let tail = q_guid_list.pop_guid().unwrap();
assert_eq!(
tail,
[0_u8, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
);
}Sourcepub fn pop_byte(&mut self) -> Result<u8>
pub fn pop_byte(&mut self) -> Result<u8>
Pop a u8 object from q byte list.
§Example
use kdb_codec::*;
fn main() {
let mut q_byte_list = K::new_byte_list(vec![0x77, 0x99, 0xae], qattribute::NONE);
let tail = q_byte_list.pop_byte().unwrap();
assert_eq!(tail, 0xae_u8);
}Sourcepub fn pop_short(&mut self) -> Result<i16>
pub fn pop_short(&mut self) -> Result<i16>
Pop a i16 object from q short list.
§Example
use kdb_codec::*;
fn main() {
let mut q_short_list = K::new_short_list(vec![12, 50], qattribute::NONE);
let tail = q_short_list.pop_short().unwrap();
assert_eq!(tail, 50_i16);
}Sourcepub fn pop_int(&mut self) -> Result<i32>
pub fn pop_int(&mut self) -> Result<i32>
Pop a i32 object from q int list.
§Example
use kdb_codec::*;
fn main() {
let mut q_int_list = K::new_int_list(vec![144000, -1, 888], qattribute::NONE);
let tail = q_int_list.pop_int().unwrap();
assert_eq!(tail, 888);
}Sourcepub fn pop_long(&mut self) -> Result<i64>
pub fn pop_long(&mut self) -> Result<i64>
Pop a i64 object from q long list.
§Example
use kdb_codec::*;
fn main() {
let mut q_long_list = K::new_long_list(vec![-86400_i64, 13800000000], qattribute::NONE);
let tail = q_long_list.pop_long().unwrap();
assert_eq!(tail, 13800000000_i64);
}Sourcepub fn pop_real(&mut self) -> Result<f32>
pub fn pop_real(&mut self) -> Result<f32>
Pop a f32 object from q real list.
§Example
use kdb_codec::*;
fn main() {
let mut q_real_list = K::new_real_list(vec![9.22_f32, -0.1], qattribute::NONE);
let tail = q_real_list.pop_real().unwrap();
assert_eq!(tail, -0.1_f32);
}Sourcepub fn pop_float(&mut self) -> Result<f64>
pub fn pop_float(&mut self) -> Result<f64>
Pop a f64 object from q float list.
§Example
use kdb_codec::*;
fn main() {
let mut q_float_list = K::new_float_list(vec![5634.7666, 120.45, 1001.3], qattribute::NONE);
let tail = q_float_list.pop_float().unwrap();
assert_eq!(tail, 1001.3);
}Sourcepub fn pop_char(&mut self) -> Result<char>
pub fn pop_char(&mut self) -> Result<char>
Pop a char object from q string.
§Example
use kdb_codec::*;
fn main() {
let mut q_string = K::new_string(String::from("speedy"), qattribute::NONE);
let tail = q_string.pop_char().unwrap();
assert_eq!(tail, 'y');
}Sourcepub fn pop_symbol(&mut self) -> Result<String>
pub fn pop_symbol(&mut self) -> Result<String>
Pop a String object from q symbol list.
§Example
use kdb_codec::*;
fn main(){
let mut q_symbol_list=K::new_symbol_list(vec![String::from("almond"), String::from("macadamia"), String::from("hazel")], qattribute::NONE);
let tail=q_symbol_list.pop_symbol().unwrap();
assert_eq!(tail, String::from("hazel"));
}Sourcepub fn pop_timestamp(&mut self) -> Result<DateTime<Utc>>
pub fn pop_timestamp(&mut self) -> Result<DateTime<Utc>>
Pop a DateTime<Utc> object from q timestamp list.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let mut q_timestamp_list = K::new_timestamp_list(
vec![Utc.ymd(2019, 8, 9).and_hms_nano(16, 28, 2, 468276775)],
qattribute::NONE,
);
let tail = q_timestamp_list.pop_timestamp().unwrap();
assert_eq!(tail, Utc.ymd(2019, 8, 9).and_hms_nano(16, 28, 2, 468276775));
}Sourcepub fn pop_month(&mut self) -> Result<NaiveDate>
pub fn pop_month(&mut self) -> Result<NaiveDate>
Pop a Date<Utc> object from q month list.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let mut q_month_list = K::new_month_list(
vec![
NaiveDate::from_ymd_opt(2011, 5, 1).unwrap(),
NaiveDate::from_ymd_opt(2004, 8, 1).unwrap(),
],
qattribute::NONE,
);
let tail = q_month_list.pop_month().unwrap();
assert_eq!(tail, NaiveDate::from_ymd_opt(2004, 8, 1).unwrap());
}Sourcepub fn pop_date(&mut self) -> Result<NaiveDate>
pub fn pop_date(&mut self) -> Result<NaiveDate>
Pop a Date<Utc> object from q date list.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let mut q_date_list = K::new_date_list(
vec![
NaiveDate::from_ymd_opt(2021, 3, 19).unwrap(),
NaiveDate::from_ymd_opt(2004, 8, 1).unwrap(),
NaiveDate::from_ymd_opt(2014, 6, 4).unwrap(),
],
qattribute::NONE,
);
let tail = q_date_list.pop_date().unwrap();
assert_eq!(tail, NaiveDate::from_ymd_opt(2014, 6, 4).unwrap());
}Sourcepub fn pop_datetime(&mut self) -> Result<DateTime<Utc>>
pub fn pop_datetime(&mut self) -> Result<DateTime<Utc>>
Pop a DateTime<Utc> object from q datetime list.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let mut q_datetime_list = K::new_datetime_list(
vec![
Utc.ymd(2018, 9, 22).and_hms_milli(4, 58, 30, 204),
Utc.ymd(2003, 12, 9).and_hms_milli(19, 58, 30, 326),
],
qattribute::NONE,
);
let tail = q_datetime_list.pop_datetime().unwrap();
assert_eq!(tail, Utc.ymd(2003, 12, 9).and_hms_milli(19, 58, 30, 326));
}Sourcepub fn pop_timespan(&mut self) -> Result<Duration>
pub fn pop_timespan(&mut self) -> Result<Duration>
Pop a Duration object from q timespan list.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let mut q_timespan_list = K::new_timespan_list(
vec![
Duration::nanoseconds(6782392639932),
Duration::nanoseconds(219849398328832),
],
qattribute::NONE,
);
let tail = q_timespan_list.pop_timespan().unwrap();
assert_eq!(tail, Duration::nanoseconds(219849398328832));
}Sourcepub fn pop_minute(&mut self) -> Result<Duration>
pub fn pop_minute(&mut self) -> Result<Duration>
Pop a Duration object from q minute list.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let mut q_minute_list = K::new_minute_list(
vec![Duration::minutes(1024), Duration::minutes(-503)],
qattribute::NONE,
);
let tail = q_minute_list.pop_minute().unwrap();
assert_eq!(tail, Duration::minutes(-503));
}Sourcepub fn pop_second(&mut self) -> Result<Duration>
pub fn pop_second(&mut self) -> Result<Duration>
Pop a Duration object from q second list.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let mut q_second_list = K::new_second_list(
vec![Duration::seconds(-32467), Duration::seconds(73984)],
qattribute::NONE,
);
let tail = q_second_list.pop_second().unwrap();
assert_eq!(tail, Duration::seconds(73984));
}Sourcepub fn pop_time(&mut self) -> Result<Duration>
pub fn pop_time(&mut self) -> Result<Duration>
Pop a Duration object from q time list.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let mut q_time_list = K::new_time_list(
vec![
Duration::milliseconds(-23587934),
],
qattribute::NONE,
);
let tail = q_time_list.pop_time().unwrap();
assert_eq!(tail, Duration::milliseconds(-23587934));
}Sourcepub fn pop(&mut self) -> Result<K>
pub fn pop(&mut self) -> Result<K>
Pop an element as K from the tail of the underlying list.
§Example
use kdb_codec::*;
use chrono::prelude::*;
use chrono::Duration;
fn main() {
let mut q_time_list = K::new_time_list(
vec![
Duration::milliseconds(902467),
Duration::milliseconds(-23587934),
],
qattribute::NONE,
);
let mut tail = q_time_list.pop().unwrap();
assert_eq!(format!("{}", tail), String::from("-06:33:07.934"));
let mut q_compound_list = K::new_compound_list(vec![
K::new_long_list(vec![10000324_i64, -43890], qattribute::NONE),
K::new_symbol(String::from("fire")),
K::new_timestamp_list(
vec![
Utc.ymd(2018, 4, 10).and_hms_nano(15, 47, 39, 758934332),
Utc.ymd(2008, 12, 4).and_hms_nano(14, 12, 7, 548932080),
],
qattribute::NONE,
),
]);
tail = q_compound_list.pop().unwrap();
assert_eq!(
format!("{}", tail),
String::from("2018.04.10D15:47:39.758934332 2008.12.04D14:12:07.548932080")
);
}Sourcepub fn remove_bool(&mut self, index: usize) -> Result<bool>
pub fn remove_bool(&mut self, index: usize) -> Result<bool>
Remove a bool object from the underlying q bool list.
§Example
use kdb_codec::*;
fn main() {
let mut q_bool_list = K::new_bool_list(vec![false, true], qattribute::NONE);
let tail = q_bool_list.remove_bool(0).unwrap();
assert_eq!(tail, false);
}Sourcepub fn remove_guid(&mut self, index: usize) -> Result<[u8; 16]>
pub fn remove_guid(&mut self, index: usize) -> Result<[u8; 16]>
Remove a [u8;16] object from the underlying q GUID list.
§Example
use kdb_codec::*;
fn main(){
let mut q_guid_list=K::new_guid_list(vec![[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15], [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]], qattribute::NONE);
let tail=q_guid_list.remove_guid(1).unwrap();
assert_eq!(tail, [1_u8,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]);
}Sourcepub fn remove_byte(&mut self, index: usize) -> Result<u8>
pub fn remove_byte(&mut self, index: usize) -> Result<u8>
Remove a u8 object from the underlying q byte list.
§Example
use kdb_codec::*;
fn main() {
let mut q_byte_list = K::new_byte_list(vec![0x77, 0x99, 0xae], qattribute::NONE);
let tail = q_byte_list.remove_byte(1).unwrap();
assert_eq!(tail, 0x99_u8);
}Sourcepub fn remove_short(&mut self, index: usize) -> Result<i16>
pub fn remove_short(&mut self, index: usize) -> Result<i16>
Remove a i16 object from the underlying q short list.
§Example
use kdb_codec::*;
fn main() {
let mut q_short_list = K::new_short_list(vec![12, 50], qattribute::NONE);
let tail = q_short_list.remove_short(0).unwrap();
assert_eq!(tail, 12_i16);
}Sourcepub fn remove_int(&mut self, index: usize) -> Result<i32>
pub fn remove_int(&mut self, index: usize) -> Result<i32>
Remove a i32 object from the underlying q int list.
§Example
use kdb_codec::*;
fn main() {
let mut q_int_list = K::new_int_list(vec![144000, -1, 888], qattribute::NONE);
let tail = q_int_list.remove_int(1).unwrap();
assert_eq!(tail, -1);
}Sourcepub fn remove_long(&mut self, index: usize) -> Result<i64>
pub fn remove_long(&mut self, index: usize) -> Result<i64>
Remove a i64 object from the underlying q long list.
§Example
use kdb_codec::*;
fn main() {
let mut q_long_list = K::new_long_list(vec![-86400_i64, 13800000000], qattribute::NONE);
let tail = q_long_list.remove_long(0).unwrap();
assert_eq!(tail, -86400_i64);
}Sourcepub fn remove_real(&mut self, index: usize) -> Result<f32>
pub fn remove_real(&mut self, index: usize) -> Result<f32>
Remove a f32 object from the underlying q real list.
§Example
use kdb_codec::*;
fn main() {
let mut q_real_list = K::new_real_list(vec![9.22_f32, -0.1], qattribute::NONE);
let tail = q_real_list.remove_real(1).unwrap();
assert_eq!(tail, -0.1_f32);
}Sourcepub fn remove_float(&mut self, index: usize) -> Result<f64>
pub fn remove_float(&mut self, index: usize) -> Result<f64>
Remove a f64 object from the underlying q float list.
§Example
use kdb_codec::*;
fn main() {
let mut q_float_list = K::new_float_list(vec![5634.7666, 120.45, 1001.3], qattribute::NONE);
let tail = q_float_list.remove_float(0).unwrap();
assert_eq!(tail, 5634.7666);
}Sourcepub fn remove_char(&mut self, index: usize) -> Result<char>
pub fn remove_char(&mut self, index: usize) -> Result<char>
Remove a char object from the underlying q string.
§Example
use kdb_codec::*;
fn main() {
let mut q_string = K::new_string(String::from("speedy"), qattribute::NONE);
let tail = q_string.remove_char(2).unwrap();
assert_eq!(tail, 'e');
}Sourcepub fn remove_symbol(&mut self, index: usize) -> Result<String>
pub fn remove_symbol(&mut self, index: usize) -> Result<String>
Remove a String object from the underlying q symbol list.
§Example
use kdb_codec::*;
fn main() {
let mut q_symbol_list = K::new_symbol_list(
vec![
String::from("almond"),
String::from("macadamia"),
String::from("hazel"),
],
qattribute::NONE,
);
let tail = q_symbol_list.remove_symbol(2).unwrap();
assert_eq!(tail, String::from("hazel"));
}Sourcepub fn remove_timestamp(&mut self, index: usize) -> Result<DateTime<Utc>>
pub fn remove_timestamp(&mut self, index: usize) -> Result<DateTime<Utc>>
Remove a DateTime<Utc> object from the underlying q timestamp list.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let mut q_timestamp_list = K::new_timestamp_list(
vec![
Utc.ymd(2019, 8, 9).and_hms_nano(16, 28, 2, 468276775),
Utc.ymd(2015, 3, 28).and_hms_nano(14, 2, 41, 46827329),
],
qattribute::NONE,
);
let tail = q_timestamp_list.remove_timestamp(0).unwrap();
assert_eq!(tail, Utc.ymd(2019, 8, 9).and_hms_nano(16, 28, 2, 468276775));
}Sourcepub fn remove_month(&mut self, index: usize) -> Result<NaiveDate>
pub fn remove_month(&mut self, index: usize) -> Result<NaiveDate>
Remove a Date<Utc> object from the underlying q month list.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let mut q_month_list = K::new_month_list(
vec![
NaiveDate::from_ymd_opt(2011, 5, 1).unwrap(),
NaiveDate::from_ymd_opt(2004, 8, 1).unwrap(),
],
qattribute::NONE,
);
let tail = q_month_list.remove_month(0).unwrap();
assert_eq!(tail, NaiveDate::from_ymd_opt(2011, 5, 1).unwrap());
}Sourcepub fn remove_date(&mut self, index: usize) -> Result<NaiveDate>
pub fn remove_date(&mut self, index: usize) -> Result<NaiveDate>
Remove a Date<Utc> object from the underlying q date list.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let mut q_date_list = K::new_date_list(
vec![
NaiveDate::from_ymd_opt(2021, 3, 19).unwrap(),
NaiveDate::from_ymd_opt(2004, 8, 1).unwrap(),
NaiveDate::from_ymd_opt(2014, 6, 4).unwrap(),
],
qattribute::NONE,
);
let tail = q_date_list.remove_date(1).unwrap();
assert_eq!(tail, NaiveDate::from_ymd_opt(2004, 8, 1).unwrap());
}Sourcepub fn remove_datetime(&mut self, index: usize) -> Result<DateTime<Utc>>
pub fn remove_datetime(&mut self, index: usize) -> Result<DateTime<Utc>>
Remove a DateTime<Utc> object from the underlying q datetime list.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let mut q_datetime_list = K::new_datetime_list(
vec![
Utc.ymd(2018, 9, 22).and_hms_milli(4, 58, 30, 204),
Utc.ymd(2003, 12, 9).and_hms_milli(19, 58, 30, 326),
],
qattribute::NONE,
);
let tail = q_datetime_list.remove_datetime(1).unwrap();
assert_eq!(tail, Utc.ymd(2003, 12, 9).and_hms_milli(19, 58, 30, 326));
}Sourcepub fn remove_timespan(&mut self, index: usize) -> Result<Duration>
pub fn remove_timespan(&mut self, index: usize) -> Result<Duration>
Remove a Duration object from the underlying q timespan list.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let mut q_timespan_list = K::new_timespan_list(
vec![
Duration::nanoseconds(6782392639932),
Duration::nanoseconds(219849398328832),
],
qattribute::NONE,
);
let tail = q_timespan_list.remove_timespan(0).unwrap();
assert_eq!(tail, Duration::nanoseconds(6782392639932));
}Sourcepub fn remove_minute(&mut self, index: usize) -> Result<Duration>
pub fn remove_minute(&mut self, index: usize) -> Result<Duration>
Remove a Duration object from the underlying q minute list.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let mut q_minute_list = K::new_minute_list(
vec![Duration::minutes(1024), Duration::minutes(-503)],
qattribute::NONE,
);
let tail = q_minute_list.remove_minute(1).unwrap();
assert_eq!(tail, Duration::minutes(-503));
}Sourcepub fn remove_second(&mut self, index: usize) -> Result<Duration>
pub fn remove_second(&mut self, index: usize) -> Result<Duration>
Remove a Duration object from the underlying q second list.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let mut q_second_list = K::new_second_list(
vec![Duration::seconds(-32467), Duration::seconds(73984)],
qattribute::NONE,
);
let tail = q_second_list.remove_second(0).unwrap();
assert_eq!(tail, Duration::seconds(-32467));
}Sourcepub fn remove_time(&mut self, index: usize) -> Result<Duration>
pub fn remove_time(&mut self, index: usize) -> Result<Duration>
Remove a Duration object from the underlying q time list.
§Example
use kdb_codec::*;
use chrono::Duration;
fn main() {
let mut q_time_list = K::new_time_list(
vec![
Duration::milliseconds(902467),
Duration::milliseconds(-23587934),
Duration::milliseconds(278958528),
],
qattribute::NONE,
);
let tail = q_time_list.remove_time(2).unwrap();
assert_eq!(tail, Duration::milliseconds(278958528));
}Sourcepub fn remove(&mut self, index: usize) -> Result<K>
pub fn remove(&mut self, index: usize) -> Result<K>
Remove an element as K object from the underlying q list.
§Example
use kdb_codec::*;
use chrono::prelude::*;
use chrono::Duration;
fn main() {
let mut q_time_list = K::new_time_list(
vec![
Duration::milliseconds(902467),
Duration::milliseconds(-23587934),
],
qattribute::NONE,
);
let mut tail = q_time_list.remove(1).unwrap();
assert_eq!(format!("{}", tail), String::from("-06:33:07.934"));
let mut q_compound_list = K::new_compound_list(vec![
K::new_long_list(vec![10000324_i64, -43890], qattribute::UNIQUE),
K::new_symbol(String::from("fire")),
K::new_timestamp_list(
vec![
Utc.ymd(2018, 4, 10).and_hms_nano(15, 47, 39, 758934332),
Utc.ymd(2008, 12, 4).and_hms_nano(14, 12, 7, 548932080),
],
qattribute::NONE,
),
]);
tail = q_compound_list.remove(0).unwrap();
assert_eq!(format!("{}", tail), String::from("`u#10000324 -43890"));
}Sourcepub fn push_pair(&mut self, key: &dyn Any, value: &dyn Any) -> Result<()>
pub fn push_pair(&mut self, key: &dyn Any, value: &dyn Any) -> Result<()>
Add a pair of key-value to a q dictionary.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let keys = K::new_int_list(vec![0, 1, 2], qattribute::NONE);
let values = K::new_date_list(
vec![
NaiveDate::from_ymd_opt(2000, 1, 9).unwrap(),
NaiveDate::from_ymd_opt(2001, 4, 10).unwrap(),
NaiveDate::from_ymd_opt(2015, 3, 16).unwrap(),
],
qattribute::NONE,
);
let mut q_dictionary = K::new_dictionary(keys, values).unwrap();
q_dictionary
.push_pair(&3, &NaiveDate::from_ymd_opt(2020, 8, 9).unwrap())
.unwrap();
assert_eq!(
format!("{}", q_dictionary),
String::from("0 1 2 3i!2000.01.09 2001.04.10 2015.03.16 2020.08.09")
);
}Sourcepub fn pop_pair(&mut self) -> Result<(K, K)>
pub fn pop_pair(&mut self) -> Result<(K, K)>
Pop the last key-vaue pair from a q dictionary.
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let keys = K::new_int_list(vec![0, 1, 2], qattribute::NONE);
let values = K::new_date_list(
vec![
NaiveDate::from_ymd_opt(2000, 1, 9).unwrap(),
NaiveDate::from_ymd_opt(2001, 4, 10).unwrap(),
NaiveDate::from_ymd_opt(2015, 3, 16).unwrap(),
],
qattribute::NONE,
);
let mut q_dictionary = K::new_dictionary(keys, values).unwrap();
q_dictionary.pop_pair().unwrap();
assert_eq!(
format!("{}", q_dictionary),
String::from("0 1i!2000.01.09 2001.04.10")
);
}Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Get the length of q object. The meaning of the returned value varies according to the type:
- atom: 1
- list: The number of elements in the list.
- table: The number of rows.
- dictionary: The number of keys.
- general null: 1
§Example
use kdb_codec::*;
use chrono::prelude::*;
fn main() {
let q_symbol_list = K::new_symbol_list(
vec![
String::from("almond"),
String::from("macadamia"),
String::from("hazel"),
],
qattribute::NONE,
);
assert_eq!(q_symbol_list.len(), 3);
let keys = K::new_int_list(vec![0, 1, 2], qattribute::NONE);
let values = K::new_date_list(
vec![
NaiveDate::from_ymd_opt(2000, 1, 9).unwrap(),
NaiveDate::from_ymd_opt(2001, 4, 10).unwrap(),
NaiveDate::from_ymd_opt(2015, 3, 16).unwrap(),
],
qattribute::NONE,
);
let mut q_dictionary = K::new_dictionary(keys, values).unwrap();
assert_eq!(q_dictionary.len(), 3);
}Sourcepub fn flip(self) -> Result<Self>
pub fn flip(self) -> Result<Self>
Create a table object from a dictionary object. Return value is either of:
Err(original value): If the argument is not a dictionary. The returned object is wrapped in error enum and can be retrieved byinto_inner.Ok(table): In case of successful conversion.
§Note
- Key type must be a symbol.
- This function does not check if lengths of columns are same.
§Example
use kdb_codec::*;
fn main() {
let q_dictionary = K::new_dictionary(
K::new_symbol_list(
vec![String::from("a"), String::from("b"), String::from("c")],
qattribute::NONE,
),
K::new_compound_list(vec![
K::new_int_list(vec![10, 20, 30], qattribute::NONE),
K::new_symbol_list(
vec![
String::from("honey"),
String::from("sugar"),
String::from("maple"),
],
qattribute::NONE,
),
K::new_bool_list(vec![false, false, true], qattribute::NONE),
]),
)
.unwrap();
let q_table = q_dictionary.flip().unwrap();
assert_eq!(
format!("{}", q_table),
String::from("+`a`b`c!(10 20 30i;`honey`sugar`maple;001b)")
);
}Sourcepub fn enkey(self, n: usize) -> Result<Self>
pub fn enkey(self, n: usize) -> Result<Self>
Convert a table into a keyed table with the first n columns ebing keys.
In case of error for type mismatch the original object is returned wrapped
in error enum and can be retrieved by into_inner.
§Example
use kdb_codec::*;
fn main() {
let q_dictionary = K::new_dictionary(
K::new_symbol_list(
vec![String::from("a"), String::from("b"), String::from("c")],
qattribute::NONE,
),
K::new_compound_list(vec![
K::new_int_list(vec![10, 20, 30], qattribute::NONE),
K::new_symbol_list(
vec![
String::from("honey"),
String::from("sugar"),
String::from("maple"),
],
qattribute::NONE,
),
K::new_bool_list(vec![false, false, true], qattribute::NONE),
]),
)
.unwrap();
let q_table = q_dictionary.flip().unwrap();
let q_keyed_table = q_table.enkey(1).unwrap();
assert_eq!(
format!("{}", q_keyed_table),
String::from("(+,`a!,10 20 30i)!(+`b`c!(`honey`sugar`maple;001b))")
);
}Sourcepub fn unkey(self) -> Result<Self>
pub fn unkey(self) -> Result<Self>
Convert a keyed table into an ordinary table. In case of error for type mismatch
the original object is returned wrapped in error enum and can be retrieved by into_inner.
§Example
use kdb_codec::*;
fn main() {
let q_dictionary = K::new_dictionary(
K::new_symbol_list(
vec![String::from("a"), String::from("b"), String::from("c")],
qattribute::NONE,
),
K::new_compound_list(vec![
K::new_int_list(vec![10, 20, 30], qattribute::NONE),
K::new_symbol_list(
vec![
String::from("honey"),
String::from("sugar"),
String::from("maple"),
],
qattribute::NONE,
),
K::new_bool_list(vec![false, false, true], qattribute::NONE),
]),
)
.unwrap();
let q_table = q_dictionary.flip().unwrap();
let q_keyed_table = q_table.enkey(1).unwrap();
assert_eq!(
format!("{}", q_keyed_table),
String::from("(+,`a!,10 20 30i)!(+`b`c!(`honey`sugar`maple;001b))")
);
let revived_table = q_keyed_table.unkey().unwrap();
assert_eq!(
format!("{}", revived_table),
String::from("+`a`b`c!(10 20 30i;`honey`sugar`maple;001b)")
);
}Trait Implementations§
Source§impl Query for K
Functional query.
impl Query for K
Functional query.